Reputation: 2309
I'm trying to generate random ProcessorId, in order to do that, I need to figure out its format.
The ProcessorId on my computer:
Get-WmiObject -Query "SELECT NAME, ProcessorId FROM Win32_Processor"
__GENUS : 2
__CLASS : Win32_Processor
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
Name : Intel(R) Core(TM) i7-3537U CPU @ 2.00GHz
ProcessorId : BFEBFBFF000306A9
PSComputerName :
The ProcessorId property from WMI has following description:
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.
This value comes from the Processor ID member of the Processor Information structure in the SMBIOS information.
Can anyone explain deeply the format of Win32_Processor.ProcessorId?
How to generate it from function __cpuid?
(The method in this answer doesn't work.)
Upvotes: 0
Views: 1142
Reputation: 2309
I still don't understand the ProcessorId description very well.
This code generate exactly the same string with Win32_Processor.ProcessorId.
#include <array>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
std::string GetProcessorId() {
std::array<int, 4> cpuInfo;
__cpuid(cpuInfo.data(), 1);
std::ostringstream buffer;
buffer
<< std::uppercase << std::hex << std::setfill('0')
<< std::setw(8) << cpuInfo.at(3)
<< std::setw(8) << cpuInfo.at(0);
return buffer.str();
}
int main(void) {
std::cout << GetProcessorId() << std::endl;
return 0;
}
Upvotes: 3