CPU ID using C++ - windows

c, c++, windows

Solution

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.

Intel introduced the unique id (serial number) instruction with the P3. But after a huge uproar over privacy, they quickly disabled that feature in subsequent CPU releases.

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

You can achieve the same thing with __cpuid function by passing "3" as the second parameter. But it won't work or return a serial number unless you have a 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".

Make and Model (BRAND String)

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. Scroll down the document to find the docs for 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

The __cpuid() instruction provided by the MSVC compiler maps "InfoType" to EAX before the call to the cpuid instruction. After that instruction returns, EAX, EBX, ECX, and EDX get copied to the CPUInfo[4] array you passed into this function.

Problem

I want to get CPU Id of my computer (windows) using c++. 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. Can anyone kindly help me on this.

Original source