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_DirectorySpecification");

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(scope, query);

foreach (ManagementObject queryObj in searcher.Get())

{

Console.WriteLine("");

Console.WriteLine("Win32_DirectorySpecification instance");

Console.WriteLine("");

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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