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.

58 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
  14. how to generate these code on client computer from which website is open?? please help

    ReplyDelete
  15. A great online marketing company for technical support inbound calls & pop up calls for tech support , PPC Call provide by osiel web.
    Call at: +91 981-142-0083 ppc management experts & Web Master.

    ReplyDelete
  16. Please how can i use these commands.. sorry i'm a dumb about this, i need to know my motherboard id

    ReplyDelete
  17. it's not working bcoz he is not to given write id of processor ..

    ReplyDelete
  18. Gravidade Código Descrição Projeto Arquivo Linha Estado de Supressão
    Erro CS0246 O nome do tipo ou do namespace "ManagementObject" não pode ser encontrado (está faltando uma diretiva using ou uma referência de assembly?) PurePaste C:\Users\gabri\Desktop\Projeto Hack\Pedrin Mira certa 3.0\PurePaste\Student\login.cs 23 Ativo

    I add System.Management namespace, but doesnt solved.

    ReplyDelete
  19. Great Article… I love to read your articles because your writing style is too good,
    its is very very helpful for all of us and I never get bored while reading your article because,
    they are becomes a more and more interesting from the starting lines until the end.
    Java training in Annanagar
    Java training in Chennai
    Java training in Chennai
    Java training in Electronic city
    Java training in Marathahalli

    ReplyDelete
  20. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    redmi service center in chennai
    xiaomi service centre chennai
    redmi service center
    mi service center
    redmi service center near me

    ReplyDelete
  21. Nice Post
    For Data Science training in Bangalore, Visit:
    Data Science training in Bangalore

    ReplyDelete
  22. Visit for AWS training in Bangalore:
    AWS training in Bangalore

    ReplyDelete
  23. Attend The Artificial Intelligence course From ExcelR. Practical Artificial Intelligence course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Artificial Intelligence course.
    Artificial Intelligence course

    ReplyDelete
  24. There are many aspects of this article on which I concur with you. You have generated synapses in my brain not used often. Thank you for getting my neurons jumping.
    Best Data Science training in Mumbai

    Data Science training in Mumbai

    ReplyDelete
  25. You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read!!
    artificial intelligence course in bangalore

    ReplyDelete
  26. Thanks for this amazing blog, visit Ogen Infosystem for creative web design and development services at an affordable price.
    Website Designing Company in Delhi

    ReplyDelete
  27. I read out your blog and I got a lot of valuable information. Visit for best Website designing company in Delhi

    ReplyDelete
  28. Here at this site really the fastidious material collection so that everybody can enjoy a lot. ExcelR Data Science Course In Pune

    ReplyDelete
  29. Great Article
    Cloud Computing Projects




    Networking Projects



    Final Year

    Projects for CSE





    JavaScript Training in Chennai



    JavaScript

    Training in Chennai




    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,

    Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.

    Angular Training

    ReplyDelete
  30. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Best Institute for Data Science in Hyderabad

    ReplyDelete
  31. I read a article under the same title some time ago, but this articles quality is much, much better. How you do this..
    Data Science Training

    ReplyDelete
  32. I have a mission that I’m just now working on, and I have been at the look out for such information ExcelR Data Analyst Course

    ReplyDelete
  33. Dear customer agar apko Shopclues lucky winner 2021 se koi call ya SMS recieve ho aur prize ke baare mai bataye aur fees bharne ke liye bole to fees bharne se pehle Shopclues prize department Whatsapp 8584806707 or Call 8584806707.

    ReplyDelete

Comments to this post

LinkWithin

Related Posts with Thumbnails