0

How to generate a System( PC/Laptop) Hardware unique ID in C#?

Please Note: The configuration is same for all the systems.

Cœur
  • 37,241
  • 25
  • 195
  • 267
aWebdesigner09
  • 257
  • 2
  • 5
  • 17
  • 1
    [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – Renatas M. May 11 '12 at 05:49
  • 2
    http://xkcd.com/221/. Your copy protection mechanism (that *is* what this is about, right?) isn't going to work anyway, so you might as well at least keep the code simple. – Jerry Coffin May 11 '12 at 05:50
  • http://stackoverflow.com/search?q=%5Bc%23%5D+hardware+id – dtb May 11 '12 at 05:58
  • possible duplicate of [How to fast get Hardware-ID in C#?](http://stackoverflow.com/questions/2333149/how-to-fast-get-hardware-id-in-c) – dtb May 11 '12 at 05:58
  • possible duplicate of [C# Creating a unique ID based on hardware ids](http://stackoverflow.com/questions/9039212/c-sharp-creating-a-unique-id-based-on-hardware-ids) – dtb May 11 '12 at 06:00

4 Answers4

2

You could use the Guid class and the NewGuid method:

var uniqueId = Guid.NewGuid();
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

I guess instead of the MAC address as it's based on the peripheral which can be changed, you can use the Processor & Motherboard id to identify the system as they will be only changed when it's damaged and creates a new system instead when changed

Func<string> SystemId = () =>
    {
        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();
        }

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

        string uniqueSystemId = id + motherBoard;
        return uniqueSystemId;
    };

    Console.WriteLine(SystemId());

Even processor can be updated so that can be ignored + i got to know even Microsoft used to have the motherboard id to identify/activate windows.

Vinod Srivastav
  • 3,644
  • 1
  • 27
  • 40
0

Generally one of the most reliable approaches is to see if you can't grab the MAC address of a network card. Generally these are unique (unless you also configured all your MAC addresses to be the same in which case you will have bigger problems :)) But I second the earlier comment. If this is for copy protection don't do it. Users will be frustrated when they switch they network cards or retire their PC to move to more recent hardware.

Mirko
  • 4,284
  • 1
  • 22
  • 19
0

You can generate a GUID not programmatically by using "Microsoft Windows SDK" tool "GUID Generator" (guidgen.exe). This tool has a different ways to represent a generated GUID, so you can further use it right in your application.

enter image description here

Sergei Danielian
  • 4,938
  • 4
  • 36
  • 58