C # Get native CPU serial number, MAC address, HDD ID, native IP address, computer name, physical memory, PC type

Source: Internet
Author: User

First, the service is introduced and then called

This article is reproduced from http://blog.sina.com.cn/s/blog_7eeb43210101hf7f.html

   Public classComputer { Public Static stringCpuID;//1.cpu Serial Number         Public Static stringMacAddress;//2.mac Serial Number         Public Static stringDiskID;//3. Hard Drive ID         Public Static stringIpAddress;//4.ip Address         Public Static stringLoginusername;//5. Login User name         Public Static stringComputerName;//6. Computer name         Public Static stringSystemType;//7. System Type         Public Static stringTotalPhysicalMemory;//8. Unit of Memory: M         Staticcomputer () {CpuID=Getcpuid (); MacAddress=getmacaddress (); DiskID=Getdiskid (); IpAddress=getipaddress (); Loginusername=GetUserName (); SystemType=Getsystemtype (); TotalPhysicalMemory=gettotalphysicalmemory (); ComputerName=GetComputerName (); }        //1. Get the CPU serial number code       Static  stringGetcpuid () {Try            {                stringCpuInfo ="";//CPU Serial NumberManagementClass MC =NewManagementClass ("Win32_Processor"); Managementobjectcollection MOC=MC.                GetInstances (); foreach(ManagementObject moinchMOC) {CpuInfo= mo. properties["Processorid"].                Value.tostring (); } MOC=NULL; MC=NULL; returnCpuInfo; }            Catch            {                return "Unknow"; }            finally            {            }        }        //2. Get the NIC hardware address       Static stringgetmacaddress () {Try            {                stringMac =""; ManagementClass MC=NewManagementClass ("Win32_NetworkAdapterConfiguration"); Managementobjectcollection MOC=MC.                GetInstances (); foreach(ManagementObject moinchMOC) {                    if((BOOL) mo["ipenabled"] ==true) {mac= mo["MacAddress"].                        ToString ();  Break; }} MOC=NULL; MC=NULL; returnmac; }            Catch            {                return "Unknow"; }            finally            {            }        }        //3. Get the hard drive ID       Static stringGetdiskid () {Try{String HDid=""; ManagementClass MC=NewManagementClass ("win32_diskdrive"); Managementobjectcollection MOC=MC.                GetInstances (); foreach(ManagementObject moinchMOC) {HDid= (string) mo. properties["Model"].                Value; } MOC=NULL; MC=NULL; returnHDid; }            Catch            {                return "Unknow"; }            finally            {            }        }        //4. Get the IP address       Static stringgetipaddress () {Try            {                stringSt =""; ManagementClass MC=NewManagementClass ("Win32_NetworkAdapterConfiguration"); Managementobjectcollection MOC=MC.                GetInstances (); foreach(ManagementObject moinchMOC) {                    if((BOOL) mo["ipenabled"] ==true)                    {                        //st=mo["IpAddress"]. ToString (); System.Array ar; Ar= (System.Array) (Mo. properties["IpAddress"].                        Value); St= Ar. GetValue (0).                        ToString ();  Break; }} MOC=NULL; MC=NULL; returnSt; }            Catch            {                return "Unknow"; }            finally            {            }        }        ///5. Login user name of the operating system       Static stringGetUserName () {Try            {                stringUN =""; Un=Environment.username; returnun; }            Catch            {                return "Unknow"; }            finally            {            }        }        //6. Get the computer name       Static stringGetComputerName () {Try            {                returnSystem.Environment.MachineName; }            Catch            {                return "Unknow"; }            finally            {            }        }        ///7 PC Type       Static stringGetsystemtype () {Try            {                stringSt =""; ManagementClass MC=NewManagementClass ("Win32_ComputerSystem"); Managementobjectcollection MOC=MC.                GetInstances (); foreach(ManagementObject moinchMOC) {St= mo["SystemType"].                ToString (); } MOC=NULL; MC=NULL; returnSt; }            Catch            {                return "Unknow"; }            finally            {            }        }        ///8. Physical Memory       Static stringgettotalphysicalmemory () {Try            {                stringSt =""; ManagementClass MC=NewManagementClass ("Win32_ComputerSystem"); Managementobjectcollection MOC=MC.                GetInstances (); foreach(ManagementObject moinchMOC) {St= mo["TotalPhysicalMemory"].                ToString (); } MOC=NULL; MC=NULL; returnSt; }            Catch            {                return "Unknow"; }            finally            {            }        }    }

C # Gets the native CPU serial number, MAC address, hard drive ID, native IP address, computer name, physical memory, PC type

Related Article

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.