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.)

Chris Watts
  • 6,197
  • 7
  • 49
  • 98

4 Answers4

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

Habib
  • 219,104
  • 29
  • 407
  • 436
  • 1
    Problem with Motherboard Serial Number is that it's rarely populated in WMI. – Chris Watts Apr 26 '12 at 06: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 '12 at 06:40
  • 1
    @CJxD, Check this out, http://www.codeproject.com/Articles/28678/Generating-Unique-Key-Finger-Print-for-a-Computer he is using BIOS+MotherBoard+Processor , looks pretty good – Habib Apr 26 '12 at 06: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?

Community
  • 1
  • 1
stephbu
  • 5,072
  • 26
  • 42
  • 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 '14 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 '14 at 05:10
1

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

Likurg
  • 2,742
  • 17
  • 22
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
Ivan Karajas
  • 1,081
  • 8
  • 14