Question

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?

Was it helpful?

Solution

You WMI installation seems somewhat broken, I have tested your getProcessorId code on a Windows 7 with UAC on, and it works fine. "Win32_Processor" is a really standard class that should be there.

Here is a link to help diagnose WMI issues: How to check the WMI repository before rebuilding it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top