FCL small application series-how to obtain network card and other hardware information

Source: Internet
Author: User

To obtain various configuration information about the running host, such as the nic mac address, IP address, hard disk partition, and hard disk number, you only need to reference system. Management. It is much simpler to implement than VC ++. For example, obtain the current enable Nic Mac and display it in the list box control:

Managementclass MC = new managementclass ("win32_networkadapterconfiguration"); <br/> managementobjectcollection MOC = MC. getinstances (); <br/> foreach (managementobject Mo in MoC) <br/>{< br/> If (bool) Mo ["ipenabled"] = true) <br/> listbox1.items. add (Mo ["macaddress"]. tostring (); </P> <p >}< br/>

The above code can only obtain the activated Nic, And the NIC must be connected. To obtain the MAC address even when the network connection is disconnected, the following code is required:

 

 Managementclass MC = new managementclass ("win32_networkadapterconfiguration"); <br/> managementobjectcollection MOC = MC. getinstances (); <br/> foreach (managementobject Mo in MoC) <br/>{< br/> If (bool) Mo ["macaddress"]! = NULL) <br/> listbox1.items. Add (Mo ["macaddress"]. tostring (); </P> <p >}< br/>

The above code can get the disconnected Nic Mac, but cannot get the disabled Nic Mac.

 

In addition, the Code for obtaining the CPU serial number and hard disk serial number is as follows:

Private void getinfo () <br/>{< br/> string cpuinfo = ""; // CPU serial number <br/> managementclass cimobject = new managementclass ("win32_processor "); <br/> managementobjectcollection MOC = cimobject. getinstances (); <br/> foreach (managementobject Mo in MoC) <br/>{< br/> cpuinfo = Mo. properties ["processorid"]. value. tostring (); <br/> console. writeline ("CPU serial number:" + cpuinfo. tostring (); <br/>}< br/> // obtain the hard disk id <br/> string Hdid; <br/> managementclass cimobject1 = new managementclass ("win32_diskdrive"); <br/> managementobjectcollection moc1 = callback (); <br/> foreach (managementobject Mo in moc1) <br/>{< br/> Hdid = (string) Mo. properties ["model"]. value; <br/> console. writeline ("hard disk serial number:" + Hdid. tostring (); <br/>}< br/>

 

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.