7

I've asked a similar question before, but I'm now reducing some of the restrictions about what I need.

I need to find a unique identifier on a computer, efficiently, with C#. It should always stay the same on any particular computer, and can be a composite of many factors - provided it's simple to retrieve.

I've thought about using the MAC address with WMI Network queries, but this is too slow as usually there are 10+ adapters. Might be better with a WHERE IPEnabled=true clause, but I think there's probably something better than this.

Ideas?

(P.S. It doesn't have to be TOTALLY unique. As long as the chance of collision is small, it's perfect.)

2
  • Are you trying to fingerprint a computer or generate a random number? Apr 25, 2012 at 6:23
  • Take a look at the following answer: stackoverflow.com/a/3474966/754042 where it's suggested to use CPU ID + HDD ID as fairly reliable unique computer identifier. Apr 25, 2012 at 6:23

4 Answers 4

18

First Get the Processor ID like following: (Add Reference to System.Management)

    ManagementObjectCollection mbsList = null;
    ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
    mbsList = mbs.Get();
    string id = "";
    foreach (ManagementObject mo in mbsList)
    {
        id = mo["ProcessorID"].ToString();
    }

//Then you can get the motherboard serial number:

    ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
    ManagementObjectCollection moc = mos.Get();
    string motherBoard = "";
    foreach (ManagementObject mo in moc)
    {
        motherBoard = (string)mo["SerialNumber"];
    }

You can concat the above two and get a unique ID

    string myUniqueID = id + motherBoard;
    Console.WriteLine(myUniqueID);

Also check out this link Finding Hardware ID, CPU ID, Motherboard ID, Hard-Disk ID of a computer

3
  • 1
    Problem with Motherboard Serial Number is that it's rarely populated in WMI. Apr 26, 2012 at 6:23
  • @CJxD, in that case you can get ID for Hard Drive as well and then make a unique id based on all three, Its not going to 100% unique but would work in most of the cases
    – Habib
    Apr 26, 2012 at 6:40
  • 1
    @CJxD, Check this out, codeproject.com/Articles/28678/… he is using BIOS+MotherBoard+Processor , looks pretty good
    – Habib
    Apr 26, 2012 at 6:43
2

Machine SID is stable as well - various ways to get to it below...

How can I retrieve a Windows Computer's SID using WMI?

2
  • Does the machine SID change with a new installation of Windows? i.e. is it operating system instance specific, or is it hardware-based ?
    – Cel
    Jun 13, 2014 at 10:11
  • 1
    It's generated each time Windows is installed. Hardware IDs such as MAC address can work, as long as you can accept software mutable that is open to tampering. The only industry standard immutable hardware id that is real "motherboard" ID is TPM, you may already have equipment that has it installed. It is still not that common.
    – stephbu
    Jun 21, 2014 at 5:10
1

Realy nice example you will see here Generating-Unique-for-a-Computer

1

You could look at this technical bulletin on Windows Product Activation. Judging by your comment, you probably don't want to go to these lengths, but maybe it can provide you with some inspiration...

WPA generates a hash based on the serial numbers of some of the following hardware items:

  • Display Adapter
  • SCSI Adapter
  • IDE Adapter
  • Network Adapter (MAC address)
  • RAM amount range
  • Processor type
  • Processor serial number
  • Hard drive
  • Hard drive volume serial number
  • CD–ROM / CD-RW / DVD-ROM
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.