What is a good unique PC identifier?

If you are on windows HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\ProductId is unique per machine/per windows install. where as in some of the other answers like the MAC address, Proc SN, and HD SN will stay the same between windows reinstalls/dual boot situations.


Some good identifiers:

  • MAC Address: It's fairly easy to get at, and it's usually unique. However, it can be spoofed/changed rather easily, so it depends on how unique it needs to be.
  • CPU Serial Number: It's not available on lots of older systems, but it's there. Check out this MSDN page. It won't change, but it's bound to a computer.
  • HDD Serial Number: It's likely to not change, but can be a nuisance if the HD fails. Check out this MSDN page.

Here is a way to uniquely identify a computer. Using System.Management to get Win32_BIOS, you can get unique values from your machine's BIOS.

See: Win32_BIOS class, http://msdn.microsoft.com/en-us/library/aa394077.aspx

using System.Management;

string UniqueMachineId()
{
    StringBuilder builder = new StringBuilder();

    String query = "SELECT * FROM Win32_BIOS";
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
    //  This should only find one
    foreach (ManagementObject item in searcher.Get())
    {
        Object obj = item["Manufacturer"];
        builder.Append(Convert.ToString(obj));
        builder.Append(':');
        obj = item["SerialNumber"];
        builder.Append(Convert.ToString(obj));
    }

return builder.ToString();
}

With similar logic, you can also step through "Win32_DiskDrive"; http://msdn.microsoft.com/en-us/library/aa394132.aspx; and get "SerialNumber" for each physical drive. In this case, the

    foreach (ManagementObject item in searcher.Get())

should find multiple items


The real answer to that question: There is no such thing.

There are several "close enough" solutions, but each one of those has it's own limitation.

All the hardware IDs - Hardware changes. And, in many cases you can change those identifiers (For example, MAC spoofing).

The SID, as I've already commented, Is not that good as well, because the SID won't change if the computer was installed from an image. The SID is generated by windows installation, if windows wasn't installed, but copied from an image, the SID won't change (although it is common to regenerate it because of a myth about "security risk" - you can't count on that).

Computer name - Well, as mentioned, They suppose to be unique, but it's not enforced in any way.

Another solution you can implement is to generate you own unique identifier and store it locally (assuming you can do such thing). Again, this solution won't work if your computer was imaged with your application.

The best solution for you really depends on what you are trying to accomplish. I had the same problem with a quite large network, and the best solution in my case was the computer's name. If you are absolutely sure that your process won't be imaged, I would generate a unique identifier using Guid because it will probably be the safest.

Tags:

C#

.Net

Guid