Get hardware information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.