程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#獲取硬件信息,

C#獲取硬件信息,

編輯:C#入門知識

C#獲取硬件信息,


  1. //硬件信息
  2. public class GF_Hardware
  3. {
  4. /// <summary>
  5. /// cpu序列號
  6. /// </summary>
  7. /// <returns></returns>
  8. public static string getID_CpuId()
  9. {
  10. string cpuInfo = "";//cpu序列號
  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. /// 硬盤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. /// 獲取網卡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. }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved