public string Getcpuinfo ()//Read CPU information {ManagementClass mobj = new ManagementClass ("Win32_processo R "); 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_physical Media "); Managementobjectcollection MOC = mobj. GetInstances (); foreach (ManagementObject mo in moc) {return mo. properties["SerialNumber"]. Value.tostring (); } return ""; }//Gets the volume label of the device hard disk public string Getdiskvolumeserialnumber () {ManagementClass MC = new Managemen Tclass ("Win32_NetworkAdapterConfiguration"); ManagementObject disk = new ManagementObject ("win32_logicaldisk.deviceid=\" D:\ ""); Disk. Get (); return disk. GetPropertyValue ("VolumeSerialNumber"). ToString (); }//Gets the serial number of the CPU public string Getcpu () {string strcpu = null; ManagementClass mycpu = new ManagementClass ("Win32_Processor"); Managementobjectcollection mycpuconnection = Mycpu.getinstances (); foreach (ManagementObject myObject in mycpuconnection) {strcpu = myobject.properties["Processor ID "]. Value.tostring (); Break } return STRCPU; }
C # Read Computer CPU,HDD information