标签:des style blog http color io os ar for
现在网上不少教程,教人通过WMI - Win32_Processor - ProcessorId来获取CPU的“序列号”,典型代码如下:
public static string GetCPUSerialNumber() { string cpuSerialNumber = string.Empty; ManagementClass mc = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { cpuSerialNumber = mo["ProcessorId"].ToString(); break; } mc.Dispose(); moc.Dispose(); return cpuSerialNumber; }
实际上,获取到的值并不是CPU的编号或者序列号,也并不是唯一的,对此,微软在msdn上有相关说明:
msdn链接:http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
msdn上的原文是这样说的:
ProcessorId
- Data type: string
- Access type: Read-only
Processor information that describes the processor features. For an x86 class CPU, the field format depends on the processor support of the CPUID instruction. If the instruction is supported, the property contains 2 (two) DWORD formatted values. The first is an offset of 08h-0Bh, which is the EAX value that a CPUID instruction returns with input EAX set to 1. The second is an offset of 0Ch-0Fh, which is the EDX value that the instruction returns. Only the first two bytes of the property are significant and contain the contents of the DX register at CPU reset—all others are set to 0 (zero), and the contents are in DWORD format.
根据msdn的说明可以知道,如果CPU支持CPUID指令的话,这个ProcessorId的值是指:“在寄存器EAX为1的时候,执行CPUID指令,返回的EAX和EDX寄存器里的数据,包含的是CPU型号、支持的指令集等信息”。如果CPU不支持CPUID指令呢?msdn没说,估计应该是空吧。
所以,ProcessorId并不是CPU的编号或者序列号,只是CPU的型号,指令集等信息。
参考链接:
[2]. An attempt to bring CPUID to C#
通过WMI - Win32_Processor - ProcessorId获取到的并不是CPU的序列号,也并不唯一
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/hhh/p/4022128.html