简体   繁体   English

使用C ++的CPU ID - windows

[英]CPU ID using C++ - windows

I want to get CPU Id of my computer (windows) using c++. 我想用c ++获取我的电脑(windows)的CPU Id。

I used this code to get it. 我使用此代码来获取它。

It outputs information something like: 它输出的信息如下:

For InfoType 0
CPUInfo[0] = 0x5
CPUInfo[1] = 0x756e6547
CPUInfo[2] = 0x6c65746e
CPUInfo[3] = 0x49656e69

For InfoType 1
CPUInfo[0] = 0xf31
CPUInfo[1] = 0x20800
CPUInfo[2] = 0x41d
CPUInfo[3] = 0xbfebfbff

For InfoType 2
CPUInfo[0] = 0x605b5001
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x7c7040

For InfoType 3
CPUInfo[0] = 0x0
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

For InfoType 4
CPUInfo[0] = 0x0
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

For InfoType 5
CPUInfo[0] = 0x40
CPUInfo[1] = 0x40
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

For InfoType 80000000
CPUInfo[0] = 0x80000008
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

For InfoType 80000001
CPUInfo[0] = 0x0
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

For InfoType 80000002
CPUInfo[0] = 0x20202020
CPUInfo[1] = 0x20202020
CPUInfo[2] = 0x20202020
CPUInfo[3] = 0x20202020

For InfoType 80000003
CPUInfo[0] = 0x47202020
CPUInfo[1] = 0x69756e65
CPUInfo[2] = 0x4920656e
CPUInfo[3] = 0x6c65746e

For InfoType 80000004
CPUInfo[0] = 0x20295228
CPUInfo[1] = 0x20555043
CPUInfo[2] = 0x30382e32
CPUInfo[3] = 0x7a4847

For InfoType 80000005
CPUInfo[0] = 0x0
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

For InfoType 80000006
CPUInfo[0] = 0x0
CPUInfo[1] = 0x0
CPUInfo[2] = 0x4008040
CPUInfo[3] = 0x0

For InfoType 80000007
CPUInfo[0] = 0x0
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

For InfoType 80000008
CPUInfo[0] = 0x2028
CPUInfo[1] = 0x0
CPUInfo[2] = 0x0
CPUInfo[3] = 0x0

I could not understand among those information which is my computer's unique CPU Id. 我无法理解那些是我计算机唯一CPU ID的信息。

Can anyone kindly help me on this. 任何人都可以帮助我。

Do you mean "serial number", "who made the processor", or the "string that identifies the make and model of the processor". 你的意思是“序列号”,“谁制作了处理器”,或“识别处理器的品牌和型号的字符串”。

Serial number: 序列号:

Unless you have a Pentium III, you do not have a "unique ID" associated with your CPU. 除非您有Pentium III,否则您没有与CPU关联的“唯一ID”。

Intel introduced the unique id (serial number) instruction with the P3. 英特尔在P3中引入了唯一的id(序列号)指令。 But after a huge uproar over privacy, they quickly disabled that feature in subsequent CPU releases. 但在对隐私产生巨大骚动之后,他们在随后的CPU版本中迅速禁用了该功能。

For the record, the instruction that executed this feature in assembly: 对于记录,在程序集中执行此功能的指令:

mov eax, 3
cpuid

The processor serial number was the concatenation of eax, edx, and ecx together 处理器序列号是eax,edx和ecx的串联

You can achieve the same thing with __cpuid function by passing "3" as the second parameter. 通过传递“3”作为第二个参数,您可以使用__cpuid函数实现相同的功能。 But it won't work or return a serial number unless you have a P3. 但除非您有P3,否则它将无法工作或返回序列号。

Vendor (who made the processor) 供应商(制造处理器)

int regs[4] = {0};
char vendor[13];
__cpuid(regs, 0);              // mov eax,0; cpuid
memcpy(vendor, &regs[1], 4);   // copy EBX
memcpy(vendor+4, &regs[3], 4); // copy EDX
memcpy(vendor+8, &regs[2], 4); // copy ECX
vendor[12] = '\0';
print("My CPU is a %s\n", vendor);

In your case, this should print "GenuineIntel". 在您的情况下,这应该打印“GenuineIntel”。

Make and Model (BRAND String) 制作和模型(BRAND字符串)

If you want all the details of the CPUID instruction, including on how to get the make, model, and stepping of your CPU, as well as the "Brand String" such as "Intel(R) Core (TM)i7-3770 CPU @ 3.4GHZ...." you can reference the Intel manual at the link below. 如果您需要CPUID指令的所有详细信息,包括如何获取CPU的品牌,型号和步进,以及“品牌字符串”,例如“Intel(R)Core(TM)i7-3770 CPU” @ 3.4GHZ ....“您可以通过以下链接参考英特尔手册。 Scroll down the document to find the docs for CPUID. 向下滚动文档以查找CPUID的文档。 I'm too lazy to type it up for you. 我懒得为你输入它。

http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2a-manual.pdf http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2a-manual.pdf

The __cpuid() instruction provided by the MSVC compiler maps "InfoType" to EAX before the call to the cpuid instruction. MSVC编译器提供的__cpuid()指令在调用cpuid指令之前将“InfoType”映射到EAX。 After that instruction returns, EAX, EBX, ECX, and EDX get copied to the CPUInfo[4] array you passed into this function. 在该指令返回后,EAX,EBX,ECX和EDX被复制到您传递给此函数的CPUInfo [4]数组中。

The value you are looking at is a manufacturer identifier. 您正在查看的值是制造商标识符。 It is the same for all Intel CPUs — it literally just says "GenuineIntel" when read in the correct order: 对于所有英特尔CPU来说都是一样的 - 当按照正确的顺序读取时,它实际上只是说“GenuineIntel”:

CPUInfo[1] = 0x756e6547 = 'Genu'
CPUInfo[3] = 0x49656e69 = 'ineI'
CPUInfo[2] = 0x6c65746e = 'ntel'

The equivalent for AMD CPUs is "AuthenticAMD". AMD CPU的等价物是“AuthenticAMD”。

For additional information, see: http://en.wikipedia.org/wiki/CPUID#EAX.3D0:_Get_vendor_ID — but, in short, there is nothing particularly unique in CPUID. 有关其他信息,请参阅: http//en.wikipedia.org/wiki/CPUID#EAX.3D0_Get_vendor_ID - 但简而言之,CPUID中没有任何特别的独特之处。

Check here . 点击这里 You need to use __cpuid. 你需要使用__cpuid。 Then you should extract the info based on the table. 然后你应该根据表格提取信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM