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

ManagementObjectSearcher searcher =

new ManagementObjectSearcher(scope, query);

foreach (ManagementObject queryObj in searcher.Get())

{

Console.WriteLine("");

Console.WriteLine("Win32_CDROMDrive instance");

Console.WriteLine("");

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

if(queryObj["Capabilities"] == null)

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

else

{

UInt16[] arrCapabilities = (UInt16[])(queryObj["Capabilities"]);

foreach (UInt16 arrValue in arrCapabilities)

{

Console.WriteLine("Capabilities: {0}", arrValue);

}

}

if(queryObj["CapabilityDescriptions"] == null)

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

else

{

String[] arrCapabilityDescriptions = (String[])(queryObj["CapabilityDescriptions"]);

foreach (String arrValue in arrCapabilityDescriptions)

{

Console.WriteLine("CapabilityDescriptions: {0}", arrValue);

}

}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

if(queryObj["PowerManagementCapabilities"] == null)

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

else

{

UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj["PowerManagementCapabilities"]);

foreach (UInt16 arrValue in arrPowerManagementCapabilities)

{

Console.WriteLine("PowerManagementCapabilities: {0}", arrValue);

}

}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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