I feel a lot of words.
Public classComputerInfo { PublicComputerInfo () {}/// <summary> ///CPU Model/// </summary> /// <returns></returns> Public stringGetcpuinfo () {ManagementObjectSearcher searcher=NewManagementObjectSearcher (@"root\cimv2","SELECT * from Win32_Processor"); foreach(ManagementObject obj2inchSearcher. Get ()) {Try { return(Obj2. GetPropertyValue ("Name"). ToString () +","+ Obj2. GetPropertyValue ("CurrentClockSpeed"). ToString () +"Mhz,"+ Environment.ProcessorCount.ToString () +"a processor"); } Catch { Continue; } } return "Unknown"; } /// <summary> ///CpuID/// </summary> /// <returns></returns> Public stringGetcpuid () {managementobjectcollection instances=NewManagementClass ("Win32_Processor"). GetInstances (); foreach(ManagementObject obj2inchinstances) { returnObj2. properties["Processorid"]. Value.tostring (); } return NULL; } /// <summary> ///get the volume label of the device's hard disk/// </summary> /// <returns></returns> Public stringGetdiskvolumeserialnumber () {ManagementClass mc=NewManagementClass ("Win32_NetworkAdapterConfiguration"); ManagementObject Disk=NewManagementObject ("win32_logicaldisk.deviceid=\ "c \""); Disk. Get (); returnDisk. GetPropertyValue ("VolumeSerialNumber"). ToString (); } /// <summary> ///get the serial number of the CPU/// </summary> /// <returns></returns> Public stringgetcpu () {stringSTRCPU =NULL; ManagementClass mycpu=NewManagementClass ("Win32_Processor"); Managementobjectcollection mycpuconnection=mycpu.getinstances (); foreach(ManagementObject MyObjectinchmycpuconnection) {STRCPU= myobject.properties["Processorid"]. Value.tostring (); Break; } returnstrcpu; } // <summary> ///Generate machine code/// </summary> /// <returns></returns> Public stringGetmnum () {stringStrnum = getcpu () + Getdiskvolumeserialnumber ();//get 24-bit CPU and hard drive serial number stringStrmnum = strnum.substring (0, -);//Remove the first 24 characters from the generated string as machine code returnStrmnum; }
/// <summary> ///Physical Memory/// </summary> /// <returns></returns> Public stringgettotalphysicalmemory () {Try { stringSt =""; ManagementClass MC=NewManagementClass ("Win32_ComputerSystem"); Managementobjectcollection MOC=MC. GetInstances (); foreach(ManagementObject moinchMOC) {St=mo. ToString (); } MOC=NULL; MC=NULL; returnSt; } Catch { return "Unknow"; } } /// <summary> ///Get computer name (ComputerName)/// </summary> /// <returns></returns> Public stringGetComputerName () {Try { returnSystem.Environment.GetEnvironmentVariable ("ComputerName"); } Catch { return "Unknow"; } } /// <summary> ///PC Type/// </summary> /// <returns></returns> Public stringGetsystemtype () {Try { stringSt =""; ManagementClass MC=NewManagementClass ("Win32_ComputerSystem"); Managementobjectcollection MOC=MC. GetInstances (); foreach(ManagementObject moinchMOC) {St=mo. ToString (); } MOC=NULL; MC=NULL; returnSt; } Catch { return "Unknow"; } } /// <summary> ///login user Name of the operating system/// </summary> /// <returns></returns> Public stringGetUserName () {Try { stringSt =""; ManagementClass MC=NewManagementClass ("Win32_ComputerSystem"); Managementobjectcollection MOC=MC. GetInstances (); foreach(ManagementObject moinchMOC) {St=mo. ToString (); } MOC=NULL; MC=NULL; returnSt; } Catch { return "Unknow"; } } }
The notes are written very clearly, just to make an archive.
Get hardware information