As per the Win32_DiskDrive
class description, the SerialNumber
and FirmwareRevision
properties aren't available on Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0. That's why you get an exception when trying to access one of them.
You may want to wrap the code that accesses these properties in a try...catch
statement; something like this:
try
{
lblSerial.Text = "Serial: " + moDisk["SerialNumber"].ToString();
}
catch (ManagementException ex)
{
lblSerial.Text = "Serial: N/A";
}
Edit: To get the serial number, you could try the Win32_PhysicalMedia.SerialNumber
property. Something like this should work:
ManagementObjectSearcher mosRefs = new ManagementObjectSearcher
("REFERENCES OF {Win32_DiskDrive.DeviceID='" + moDisk["DeviceID"].ToString() + "'} WHERE ResultClass=Win32_DiskDrivePhysicalMedia");
foreach (ManagementObject moRef in mosRefs.Get())
{
ManagementObject moMedia = new ManagementObject(moRef["Antecedent"].ToString());
lblSerial.Text = "Serial: " + moMedia["SerialNumber"].ToString();
}