ComputerTool.cs 867 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Management;
  2. namespace Y.Utils.ComputerUtils
  3. {
  4. public class ComputerTool
  5. {
  6. public static string GetCpuId()
  7. {
  8. ManagementClass mc = null;
  9. ManagementObjectCollection moc = null;
  10. string ProcessorId = "";
  11. try
  12. {
  13. mc = new ManagementClass("Win32_Processor");
  14. moc = mc.GetInstances();
  15. foreach (ManagementObject mo in moc)
  16. {
  17. ProcessorId = mo.Properties["ProcessorId"].Value.ToString();
  18. }
  19. return ProcessorId;
  20. }
  21. catch
  22. {
  23. return "unknow";
  24. }
  25. finally
  26. {
  27. if (moc != null) moc.Dispose();
  28. if (mc != null) mc.Dispose();
  29. }
  30. }
  31. }
  32. }