C # obtain hardware information,

Source: Internet
Author: User

C # obtain hardware information,

  1. // Hardware information
  2. Public class GF_Hardware
  3. {
  4. /// <Summary>
  5. /// Cpu serial number
  6. /// </Summary>
  7. /// <Returns> </returns>
  8. Public static string getID_CpuId ()
  9. {
  10. String cpuInfo = ""; // cpu serial number
  11. ManagementClass cimobject = new ManagementClass ("Win32_Processor ");
  12. ManagementObjectCollection moc = cimobject. GetInstances ();
  13. Foreach (ManagementObject mo in moc)
  14. {
  15. CpuInfo = mo. Properties ["ProcessorId"]. Value. ToString ();
  16. }
  17. Return cpuInfo;
  18. }
  19.  
  20. /// <Summary>
  21. /// Hard disk ID
  22. /// </Summary>
  23. /// <Returns> </returns>
  24. Public static string getID_HardDiskId ()
  25. {
  26. String HDid = "";
  27. ManagementClass cimobject = new ManagementClass ("Win32_DiskDrive ");
  28. ManagementObjectCollection moc = cimobject. GetInstances ();
  29. Foreach (ManagementObject mo in moc)
  30. {
  31. HDid = (string) mo. Properties ["Model"]. Value;
  32. }
  33. Return HDid;
  34. }
  35.  
  36. /// <Summary>
  37. /// Obtain the NIC MacAddress
  38. /// </Summary>
  39. /// <Returns> </returns>
  40. Public static string getID_NetCardId ()
  41. {
  42. String NCid = "";
  43. ManagementClass mc = new ManagementClass ("Win32_NetworkAdapterConfiguration ");
  44. ManagementObjectCollection moc = mc. GetInstances ();
  45. Foreach (ManagementObject mo in moc)
  46. {
  47. If (bool) mo ["IPEnabled"] = true)
  48. NCid = mo ["MacAddress"]. ToString ();
  49. Mo. Dispose ();
  50. }
  51. Return NCid;
  52. }
  53.  
  54.  
  55.  
  56. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.