المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Error Getting Processor Id



C# Programming
07-20-2010, 05:16 AM
Gentleman,

I wrote an application that needs to get the Processor ID from the OS. I have been using it exactly as designed below for the last several years on Win XP and Vista. A recent user of this app reported to me that he is getting an error that would indicate that the Processor Id is not being returned as designed. Now, the only difference that I know of is that he is using Windows 7. Question: is there any reason why the Management Class call that I have here will not work on Win 7?...or should I look for a different problem elsewhere? Thank you in advance...Pat

public string GetProcId()
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuSerial == string.Empty || cpuSerial == null)
{
// only return cpuSerial from first CPU
cpuSerial = mo.Properties["ProcessorId"].Value.ToString();
cpuSerial = cpuSerial.ToUpper().Trim();
}
}
return cpuSerial;
}