Is this the right way to get the grand total of processors with WMI on a multi-cpu system?

Posted by John Sheares on Stack Overflow See other posts from Stack Overflow or by John Sheares
Published on 2010-04-05T06:58:04Z Indexed on 2010/04/05 7:03 UTC
Read the original article Hit count: 325

Filed under:
|
|

I don't have access to a multi-socketed computer, so I am unsure if the following will get the grand total of processors and logical processors. I assume ManagementObjectSearcher will return an instance for each socketed CPU and I just keep a running total?

int totalCPUs = 0; int totalLogicalCPUs = 0;

ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_ComputerSystem"); foreach (var mo in mos.Get()) { string num = mo.Properties["NumberOfProcessors"].Value.ToString(); totalCPUs += Convert.ToInt32(num);

num = mo.Properties["NumberOfLogicalProcessors"].Value.ToString(); totalLogicalCPUs += Convert.ToInt32(num);

}

© Stack Overflow or respective owner

Related posts about wmi

Related posts about processors