C # Read Computer hardware information

Source: Internet
Author: User

In the class to see colleagues in the use of the dongle, feel that they can also achieve a similar dongle read computer CPU and MAC address of the program, try to do one. The program is relatively simple, but the read function has been implemented.

1   Public classHardwarehelper2     {3         /// <summary>4         ///gets all the CPU serial numbers for this machine (does not return null)5         /// </summary>6         /// <returns></returns>7          Public Staticlist<string>Getcpuid ()8         {9list<string> list =Newlist<string>();Ten             Try One             { A                 //get the CPU serial number code -ManagementClass MC =NewManagementClass ("Win32_Processor"); -Managementobjectcollection MOC =MC. GetInstances (); the                 foreach(ManagementObject moinchMOC) -                 { -List. ADD (Mo. properties["Processorid"]. Value.tostring ()); -                 } +             } -             Catch +             { A  at             } -             returnlist; -         } -         /// <summary> -         ///get native all NIC IP address and MAC address (IP|MAC), does not return null -         /// </summary> in         /// <returns></returns> -          Public Staticlist<string>getnetaddress () to         { +list<string> list =Newlist<string>(); -             Try the             { *                 //Get the network adapter $ManagementClass MC =NewManagementClass ("Win32_NetworkAdapterConfiguration");Panax NotoginsengManagementobjectcollection MOC =MC. GetInstances (); -                 stringmac, IP; the                 foreach(ManagementObject moinchMOC) +                 { A                     if((BOOL) mo["ipenabled"] ==true) the                     { +Mac = mo["MacAddress"]. ToString (). Replace (":","-"); -Array ar = (System.Array) (Mo. properties["IpAddress"]. Value); $ip = ar. GetValue (0). ToString (); $List. ADD (IP +"|"+mac); -                     } -                 } the             } -             CatchWuyi             { the  -             } Wu             returnlist; -         } About}

Attention:

When using ManagementClass, you need to introduce System.Management assemblies and program namespaces.

C # Read Computer hardware information

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.