I'm using this code to fetch the processor id:
public static string getProcessorId()
{
var mc = new ManagementClass("Win32_Processor");
var moc = mc.GetInstances();
foreach (var mo in moc)
{
return mo.Properties["ProcessorId"].Value.ToString();
}
return "Unknown";
}
I'm running Windows 7 32-bit, Visual Studio 2008. Unfortunately, a "Not found" exception is being raised by the mc.GetInstances() method call.
Here's a similar bit of code (fetch HDD serial):
public static string getVolumeSerialNumber()
{
var disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
return disk["VolumeSerialNumber"].ToString();
}
This code also fails - the "disk.Get()" method raises an "Invalid class" exception.
I've run this code with UAC turned off & on - nothing helps.
What am I doing wrong?