ComputerTool.cs 983 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. ManagementClass mc = null;
  14. ManagementObjectCollection moc = null;
  15. string ProcessorId = "";
  16. try
  17. {
  18. mc = new ManagementClass("Win32_Processor");
  19. moc = mc.GetInstances();
  20. foreach (ManagementObject mo in moc)
  21. {
  22. ProcessorId = mo.Properties["ProcessorId"].Value.ToString();
  23. }
  24. return ProcessorId;
  25. }
  26. catch
  27. {
  28. return "unknow";
  29. }
  30. finally
  31. {
  32. if (moc != null) moc.Dispose();
  33. if (mc != null) mc.Dispose();
  34. }
  35. }
  36. }
  37. }