Search code examples
c#.nethardwarecpuhardware-id

How to fast get Hardware-ID in C#?


I need in my program to tie a license to a hardware ID. I tried use WMI, but it still slow.

I need, for example, CPU, HDD, and motherboard info.


Solution

  • For more details refer to this link

    The following code will give you CPU ID:

    namespace required System.Management

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

    For Hard disk ID and motherboard id details refer this-link

    To speed up this procedure, make sure you don't use SELECT *, but only select what you really need. Use SELECT * only during development when you try to find out what you need to use, because then the query will take much longer to complete.