Method of obtaining CPU number by C

  • 2021-07-22 11:10:40
  • OfStack

In this paper, the method of obtaining CPU number by C # is described as an example. Share it for your reference. The details are as follows:


/// <summary>
/// Gets the cpu  Numbering .
/// Reference required using System.Management;
/// </summary>
/// <returns></returns>
public string GetCpuId()
{
   string cpuInfo = "";
   ManagementClass cimobject = new ManagementClass("Win32_Processor");
   ManagementObjectCollection moc = cimobject.GetInstances();
   foreach (ManagementObject mo in moc)
   {
     cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
   }
   return cpuInfo;
}

I hope this article is helpful to everyone's C # programming.


Related articles: