经过WMI - Win32_Processor - ProcessorId获取到的并非CPU的序列号,也并不惟一

如今网上很多教程,教人经过WMI - Win32_Processor - ProcessorId来获取CPU的“序列号”,典型代码以下:spa

        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上有相关说明:code

msdn连接:http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspxorm

msdn上的原文是这样说的:blog

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.get

 

根据msdn的说明能够知道,若是CPU支持CPUID指令的话,这个ProcessorId的值是指:“在寄存器EAX为1的时候,执行CPUID指令,返回的EAX和EDX寄存器里的数据,包含的是CPU型号、支持的指令集等信息”。若是CPU不支持CPUID指令呢?msdn没说,估计应该是空吧。input

 

因此,ProcessorId并非CPU的编号或者序列号,只是CPU的型号,指令集等信息。string

 

参考连接:it

[1]. Win32_Processor classio

[2]. An attempt to bring CPUID to C#

相关文章
相关标签/搜索