Win32 Classes in Windows OS are groups of
Hardware, Software or OS
classes (along with others) that contains features and attributes depending on the class selected. My problem is with the
Win32_CDROMDrive that has many properties of the connected ODD device like
Caption
,
Description
,
Drive
,
Id
,
Name
, etc.). The problem (specifically) is with the property
SerialNumber
which returns the identifier of the drive by the manufacture.
It returns a null in a case
and returns an actual value in a different case!
I just want to get the
SerialNumber
solely like this
SELECT SerialNumber FROM Win32_CDROMDrive
without extracting the whole values and choosing between them.
What I have tried:
Here is how to list all the properties of the
Win32_CDROMDrive
(
SerialNumber
exist with an actual value).
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_CDROMDrive");
foreach (ManagementObject mo in searcher.Get())
foreach (PropertyData pd in mo.Properties)
Console.WriteLine("{0}:- {1}", pd.Name, pd.Value);
To get a single property value (like
Name
) from the same class the query is changed to (and it will return the value of
Name
).
var searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_CDROMDrive");
To get the value of the
SerialNumber
property the query is changed to (and here is the problem,
it will return null)
var searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_CDROMDrive");
More odd behavior is when I try to get the value of a property with other random one like this (it will return actual values)
var searcher = new ManagementObjectSearcher("SELECT SerialNumber, SCSIPort FROM Win32_CDROMDrive");
While if with a property with a different initial (it will return null for the
SerialNumber
and actual value for the
Name
)
var searcher = new ManagementObjectSearcher("SELECT SerialNumber, Name FROM Win32_CDROMDrive");
Again can the
SerialNumber
be extracted solely like this
SELECT SerialNumber FROM Win32_CDROMDrive
without extracting the whole values and choosing between them.