Saturday, March 6, 2010

Finding Hardware ID, CPU ID, Motherboard ID, Hard-Disk ID of a computer

Many a times it is required that we find the hardware id of a system. The hardware can be Motherboard, processor or hard-disk. The manufactures of these devices embed a unique id to them which can be retrieved anytime. Further they are sometimes also used to get the unique id for the machine. In this post I am going to show how to retrieve these id's in C#.net code. First of all we would be requiring the following namespace:

System.Management

The following code will retrieve the CPU ID (processor id):

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();
}


The following code will generate hard-disk id:

ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");
dsk.Get();
string id = dsk["VolumeSerialNumber"].ToString();


The following code will generate motherboard id:

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

By using these we can generate the id's of the respective hardware. Another use of these can be to generate a unique id for that system. But one should be aware that these id's are not always unique. It has been seen that some hardware manufactures use a single id for a whole lot of hardware. In this scenario we can use combination of all these id's to generate a single unique id for the machine.

22 comments:

  1. Very informative. Thanks for the code.

    ReplyDelete
  2. Nice information. Do share any more updates.

    ReplyDelete
  3. Good post! It really helped me in finding the CPU id from my laptop. Further as you had advised i created a unique id or the system by combination of cpu-id, motherboard id and hard disk id. Though the end key is quite long... i managed it by taking only the last 5 characters of each keys. Thus i had a 15 digit unique id for the system.

    Once again thanks for the wonderful article.

    ReplyDelete
  4. the information is given is informative. but i need the code to get the client CPU ID,Mother board ID, and Hard Disc Id

    ReplyDelete
    Replies
    1. what are you - a moron? The code IS given

      Delete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. Thanks for the code for generating motherboard id, cpu id, hard drive id and hardware id for uniquely identifying any machine. This helped me in identifying a particular user and generating license key for them.

    ReplyDelete
  7. can anyone tell me how to use this code..i tried but System.Management namespace does not have ManagementObjectCollection...

    ReplyDelete
    Replies
    1. First add System.Management with References

      Delete
  8. Thanks for the code. It helped me a lot !

    ReplyDelete
  9. Hello and Hi Jai :) i'm Brinda . working as software developer.

    ur code is useful for us. but i hav one doubt .u written motherboard id code know . that result return only empty string. can u plz explain the problem.

    ReplyDelete
    Replies
    1. Can you tell of which make is the motherboard ? It is generally seen that the motherboard id is returned only for those motherboard chip-sets that are using standardized chips. Some Chinese chip-sets are using duplicate chip-sets in the motherboard and they do not carry any inbuilt serial no.

      I hope this helps.

      Delete
    2. Hi, when run on virtual machines the motherboard ID returned is NONE.

      Delete
    3. That's correct. When we use virtual machine it is basically running on top of the OS which is giving it a virtual hardware layer under it, but in actual the hardware is in control of the under-laying OS and not the virtual machine. So the .net code I have provided will not give the motherboard ID. By the way which virtual machine software you are using, VMWare or MS VM ?

      Delete
    4. can we change de hwid of virtual machine for soft protection remote test? thnks

      Delete
    5. On MY LENOVO With Intel Motherboard,
      Mother Board ID is an empty string ,,

      Delete
  10. Hi, Thank you. How can i use it in ASP.NET? Is is possible?

    ReplyDelete
  11. thank you, it's great, is it work on all of the windows? i test it on windows seven

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  13. Does this work on Windows XP SP3?
    It didn't work for me, even when it works on Windows 7, 8 and 8.1

    ReplyDelete

Comments to this post

LinkWithin

Related Posts with Thumbnails