Method for C to read computer CPU and HDD information

  • 2021-07-13 06:08:08
  • OfStack

This paper describes the method of C # reading CPU and HDD information of computer with examples. Share it for your reference. The details are as follows:

Here, C # is used to read the information of CPU and HDD of computer, which is suitable for Windows


public string getCpuInfo() // Read CPU Information 
{
 ManagementClass mobj = new ManagementClass("Win32_Processor");
 ManagementObjectCollection moc = mobj.GetInstances();
 foreach (ManagementObject mo in moc)
 {
  return mo.Properties["ProcessorId"].Value.ToString();
 }
 return "";
}
public string getHddInfo() // Read hard disk information 
{
 ManagementClass mobj = new ManagementClass("Win32_PhysicalMedia");
 ManagementObjectCollection moc = mobj.GetInstances();
 foreach (ManagementObject mo in moc)
 {
  return mo.Properties["SerialNumber"].Value.ToString();
 }
 return "";
}

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


Related articles: