Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique computer ID

I'm looking for a way to get unique computer ID.

According to this post I can't use processor ID for this purpose. Can I take motherboard ID? What is the best way to identify the computer?

like image 454
StuffHappens Avatar asked Aug 13 '10 07:08

StuffHappens


People also ask

Do computers have a unique ID?

A universally unique identifier (UUID) is a 128-bit label used for information in computer systems. The term globally unique identifier (GUID) is also used. When generated according to the standard methods, UUIDs are, for practical purposes, unique.

Is device ID unique for laptop?

Each device in Windows has it's own unique identifier known as the Hardware ID. The Device ID is the identifier of the PC itself.

What is mean by unique identity in computer?

Answer. A unique identifier (UID) is an identifier that marks that particular record as unique from every other record. It allows the record to be referenced in the Summon Index without confusion or unintentional overwriting from other records. Examples.


1 Answers

Like you've said CPU Id wont be unique, however you can use it with another hardware identifier to create your own unique key.

Reference assembly System.Management

So, use this code to get the CPU ID:

string cpuInfo = string.Empty; ManagementClass mc = new ManagementClass("win32_processor"); ManagementObjectCollection moc = mc.GetInstances();  foreach (ManagementObject mo in moc) {      cpuInfo = mo.Properties["processorID"].Value.ToString();      break; } 

Then use this code to get the HD ID:

string drive = "C"; ManagementObject dsk = new ManagementObject(     @"win32_logicaldisk.deviceid=""" + drive + @":"""); dsk.Get(); string volumeSerial = dsk["VolumeSerialNumber"].ToString(); 

Then, you can just combine these two serials to get a uniqueId for that machine:

string uniqueId = cpuInfo + volumeSerial; 

Obviously, the more hardware components you get the IDs of, the greater the uniqueness becomes. However, the chances of the same machine having an identical CPU serial and Hard disk serial are already slim to none.

like image 62
djdd87 Avatar answered Sep 28 '22 06:09

djdd87