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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With