How to get CPU Id by using C# with .Net classes

By using ManagementObjectSearcher class in System.Management; namespace you can get your hardware information such as CPU Id. take a look at this piece of code:

 

  1.        static void Main(string[] args)
  2.         {
  3.             var managementObjectSearcher = new ManagementObjectSearcher("SELECT ProcessorId FROM Win32_Processor");
  4.             var oCollection = managementObjectSearcher.Get();
  5.             foreach (ManagementObject item in oCollection)
  6.             {
  7.                 var myProcessor = (string)item["ProcessorId"];
  8.                 Console.WriteLine("Processor Id: {0}", myProcessor);
  9.             }
  10.         }

Have fun!

 


Tags: C#


comments powered by Disqus