WMI Windows 7 vs Server 2003 R2 Problem

Posted by Shahmir Javaid on Stack Overflow See other posts from Stack Overflow or by Shahmir Javaid
Published on 2010-03-09T06:13:02Z Indexed on 2010/03/09 6:21 UTC
Read the original article Hit count: 612

Filed under:
|

I have the below procedures running one after the Other. It seems to work fine in Windows 7 but fails on Windows Server 2003 R2. Any Ideas Why? Am i suppose to be disposing

For Cpu

ManagementObjectSearcher cpuSearcher = new ManagementObjectSearcher("root\\CIMv2", "SELECT *  FROM Win32_Processor");

foreach (ManagementObject cpuObj in cpuSearcher.Get())
{
cpu.Add(new cpuinfo(cpuObj["Name"].ToString()));
cpuObj.Dispose();

}

cpuSearcher.Dispose();

For Memory

ManagementObjectSearcher memSearcher = new ManagementObjectSearcher("root\\CIMv2", "SELECT Capacity FROM Win32_PhysicalMemory");

//Get total Memory
foreach (ManagementObject memObj in memSearcher.Get())
{
    MemTotal += (Int64.Parse((memObj["Capacity"].ToString())));
    memObj.Dispose();
}

Any Help would be apreaciated

© Stack Overflow or respective owner

Related posts about c#

Related posts about wmi