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