Sunday, 8 November 2009

WMI Exception

I was debugging an exception coming back from the ManagementObjectCollection class in .NET. Basically an exception was coming back from COM which had a HRESULT of 0x800705af (-2147023441). My code was as follows:
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
int count = moc.Count;
foreach (ManagementObject mo in moc)
{
// Only get first CPU.
CpuSerial = (string) mo["processorID"].ToString().Trim();
break;
}

The exception is thrown on the third line when accessing moc.Count. Googling the error code revealed pretty much nothing. As the code is trying to get the CPU serial I thought I'd right click on My Computer and seeing if the CPU information appeared. Bingo, even that wasn't working. The Processor and Installed memory (RAM) were both showing Not Available. I was wondering if anyone else has had similar problems? A reboot fixed the problem. I'm using windows 7 (but it wasn't my idea).

0 comments: