經過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#

相關文章
相關標籤/搜索