ComputerTool.cs 956 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Management;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Y.Utils.ComputerUtils
  8. {
  9. public class ComputerTool
  10. {
  11. public static string GetCpuId()
  12. {
  13. try
  14. {
  15. //获取CPU序列号代码
  16. string cpuInfo = "";//cpu序列号
  17. ManagementClass mc = new ManagementClass("Win32_Processor");
  18. ManagementObjectCollection moc = mc.GetInstances();
  19. foreach (ManagementObject mo in moc)
  20. {
  21. cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
  22. }
  23. moc = null;
  24. mc = null;
  25. return cpuInfo;
  26. }
  27. catch
  28. {
  29. return "unknow";
  30. }
  31. finally
  32. {
  33. }
  34. }
  35. }
  36. }