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

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(scope, query);

foreach (ManagementObject queryObj in searcher.Get())

{

Console.WriteLine("");

Console.WriteLine("Win32_Directory instance");

Console.WriteLine("");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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