SoFunction
Updated on 2025-03-07

Method for reading computer CPU and HDD information in C#

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

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

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

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