try

{

ConnectionOptions connection = new ConnectionOptions();

connection.Username = userNameBox.Text;

connection.Password = passwordBox.Text;

connection.Authority = "ntlmdomain:Finance123";

ManagementScope scope = new ManagementScope(

"\\dell417\root\CIMV2", connection);

scope.Connect();

ObjectQuery query= new ObjectQuery(

"SELECT * FROM Win32_Desktop");

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(scope, query);

foreach (ManagementObject queryObj in searcher.Get())

{

Console.WriteLine("");

Console.WriteLine("Win32_Desktop instance");

Console.WriteLine("");

Console.WriteLine("BorderWidth: {0}", queryObj["BorderWidth"]);

Console.WriteLine("Caption: {0}", queryObj["Caption"]);

Console.WriteLine("CoolSwitch: {0}", queryObj["CoolSwitch"]);

Console.WriteLine("CursorBlinkRate: {0}", queryObj["CursorBlinkRate"]);

Console.WriteLine("Description: {0}", queryObj["Description"]);

Console.WriteLine("DragFullWindows: {0}", queryObj["DragFullWindows"]);

Console.WriteLine("GridGranularity: {0}", queryObj["GridGranularity"]);

Console.WriteLine("IconSpacing: {0}", queryObj["IconSpacing"]);

Console.WriteLine("IconTitleFaceName: {0}", queryObj["IconTitleFaceName"]);

Console.WriteLine("IconTitleSize: {0}", queryObj["IconTitleSize"]);

Console.WriteLine("IconTitleWrap: {0}", queryObj["IconTitleWrap"]);

Console.WriteLine("Name: {0}", queryObj["Name"]);

Console.WriteLine("Pattern: {0}", queryObj["Pattern"]);

Console.WriteLine("ScreenSaverActive: {0}", queryObj["ScreenSaverActive"]);

Console.WriteLine("ScreenSaverExecutable: {0}", queryObj["ScreenSaverExecutable"]);

Console.WriteLine("ScreenSaverSecure: {0}", queryObj["ScreenSaverSecure"]);

Console.WriteLine("ScreenSaverTimeout: {0}", queryObj["ScreenSaverTimeout"]);

Console.WriteLine("SettingID: {0}", queryObj["SettingID"]);

Console.WriteLine("Wallpaper: {0}", queryObj["Wallpaper"]);

Console.WriteLine("WallpaperStretched: {0}", queryObj["WallpaperStretched"]);

Console.WriteLine("WallpaperTiled: {0}", queryObj["WallpaperTiled"]);

}

Close();

}

catch(ManagementException err)

{

MessageBox.Show("An error occurred while querying for WMI data: " + err.Message);

}

catch(System.UnauthorizedAccessException unauthorizedErr)

{

MessageBox.Show("Connection error (user name or password might be incorrect): " + unauthorizedErr.Message);

}

Advertisements