Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am trying to get an unique CPU ID

Tags:

c#

cpu

I am using the code below to get a unique CPU ID, i found various samples on the web using this. However. By chance I happen to own 2 Asus Laptops. One is a quad core i5 the other an heavy duty i7 octocore both are 64 bit machines.. To my big surprise they both produce the same "unique" CPU ID ???.

So this code isnt working for me, are there other methods to get unique CPU ids or do i do something wrong here. What I hope to get is a number that specific for each CPU that is made

string cpuID = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();

foreach (ManagementObject mo in moc)
{
 if (cpuID == "")
 {
      //Remark gets only the first CPU ID
      cpuID = mo.Properties["processorID"].Value.ToString();

 }
}
return cpuID;
like image 988
user613326 Avatar asked Oct 25 '25 07:10

user613326


2 Answers

try

ManagementClass managClass = new ManagementClass("win32_processor");
ManagementObjectCollection managCollec = managClass.GetInstances();

foreach (ManagementObject managObj in managCollec)
{
    cpuInfo = managObj.Properties["processorID"].Value.ToString();
    break;
}

working fine here...

like image 111
DeMama Avatar answered Oct 27 '25 22:10

DeMama


Maybe the UUID property of the Win32_ComputerSystemProduct object will suit your needs. It is supposed to be unique per-motherboard, as long as the manufacturer configures it in the first place. It's not too common for the CPU to move around without the motherboard coming along for the ride, anyways.

like image 33
deGoot Avatar answered Oct 27 '25 22:10

deGoot