Getting Processsor ID without ManagementClass
-
Hello all, The following code will retrieve a unique processor ID (for the first processor) using the .NET Frameworks System.Management.ManagementClass class:
public static string GetCPUId()
{
string cpuInfo = string.Empty;ManagementClass mgr = new ManagementClass("Win32\_Processor"); ManagementObjectCollection mgrCollection = mgr.GetInstances(); foreach (ManagementObject mgrItem in mgrCollection) { if (cpuInfo == string.Empty) { cpuInfo = mgrItem.Properties\["ProcessorId"\].Value.ToString(); break; } } return cpuInfo;
}
However I need to do the same thing using DllImport/Interop. Does anybody know how to do this?
-
Hello all, The following code will retrieve a unique processor ID (for the first processor) using the .NET Frameworks System.Management.ManagementClass class:
public static string GetCPUId()
{
string cpuInfo = string.Empty;ManagementClass mgr = new ManagementClass("Win32\_Processor"); ManagementObjectCollection mgrCollection = mgr.GetInstances(); foreach (ManagementObject mgrItem in mgrCollection) { if (cpuInfo == string.Empty) { cpuInfo = mgrItem.Properties\["ProcessorId"\].Value.ToString(); break; } } return cpuInfo;
}
However I need to do the same thing using DllImport/Interop. Does anybody know how to do this?
MrEyes wrote:
The following code will retrieve a unique processor ID
According to this web page[^] the processorID is not unique at all. You are confusing with the processor serial number which might be available through the UniqueID field of WMI, but this feature may be absent or disabled (in which case WMI returns a null value). The default state is: disabled. To access such features without WMI you need low-level code, say C + assembly, that executes the CPUID instruction and returns some register values; plus of course the necessary P/Invoke stuff to interface to the native code. For more info on CPUID, search for "Intel CPUID" and you will find utilities and documentation (Intel App Note 485). :)
Luc Pattyn [My Articles] [Forum Guidelines]