This article mainly introduces C # programming to obtain client computer hardware and system Information function, can realize the client system CPU, hard disk, motherboard and other hardware information and client operating system, IP, Mac and other information operation skills, the need for friends can refer to the next
This article describes the C # programming to obtain the client computer hardware and system information functions. Share to everyone for your reference, as follows:
This uses C # to obtain client computer hardware and system information, including CPU, hard disk, IP, MAC address, operating system, and so on.
1, the project reference System.Management Library.
2. Create a HardwareHandler.cs class file
Using system;using system.collections.generic;using system.linq;using system.text;using System.Management;namespace mystudy.utility{//<summary>///Computer Hardware processing class///</summary> public class Hardwarehandler {public enum Wmipath {//Hardware win32_processor,//CPU processor win32_physicalmemory,//physical memory strip Win32_Keyboard, Keyboard Win32_pointingdevice,//point input device, including mouse. Win32_floppydrive,//floppy drive win32_diskdrive,//Hard drive win32_cdromdrive,//optical drive Win32_baseboard, Motherboard Win32_BIOS,//BIOS chip Win32_ParallelPort,//Win32_serialport,//serial Port win32_s Erialportconfiguration,//serial port configuration Win32_sounddevice,//Multimedia settings, generally refers to the sound card. Win32_systemslot,//Motherboard sockets (ISA & PCI & AGP) Win32_usbcontroller,//USB controller Win32_NetworkAdapter, Network adapter Win32_NetworkAdapterConfiguration,//network adapter settings Win32_Printer,//printer Win32_printerconfiguratio N,//printer settingsWin32_PrintJob,//Printer task Win32_tcpipprinterport,//Printer port Win32_potsmodem,//MODEM Win32_potsmodem Toserialport,//MODEM port Win32_DesktopMonitor,//Monitor win32_displayconfiguration,//Graphics Win32_displaycont Rollerconfiguration,//Graphics settings Win32_VideoController,//graphics card details. Win32_videosettings,//display mode supported by the graphics card. Operating system Win32_TimeZone,//time zone win32_systemdriver,//Driver win32_diskpartition,//disk partition Win32_lo Gicaldisk,//Logical Disk win32_logicaldisktopartition,//Logical disk in the same partition and the beginning and ending position. Win32_LogicalMemoryConfiguration,//Logical memory configuration Win32_PageFile,//System page file information win32_pagefilesetting,//page file settings Win32_bootconfiguration,//System boot Configuration Win32_ComputerSystem,//Computer Information brief Win32_OperatingSystem,//operating system Information Win32 _startupcommand,//System automatic Start Program Win32_Service,//System installation Service Win32_Group,//System Management Group Win32_groupuser, System group account Win32_UserAccount,//user account Win32_Process,//System process Win32_thread,//System thread Win32_Share,//Shared win32_networkclient,//Installed network client Win32_networkpro Tocol,//Installed network protocol}//<summary>//CPU information//</summary>//<returns></returns> public void CpuInfo () {try {ManagementClass mc = new ManagementClass (WMIPath.Win32_Processor.ToS Tring ()); Managementobjectcollection MOC = MC. GetInstances (); foreach (ManagementObject mo in MoC) {Console.WriteLine ("CPU Number:" + mo.) properties["Processorid"]. Value); Console.WriteLine ("CPU Model:" + mo.) properties["Name"]. Value); Console.WriteLine ("CPU Status:" + mo.) properties["Status"]. Value); Console.WriteLine ("Host name:" + mo.) properties["SystemName"]. Value); }} catch {Console.WriteLine ("Erroe"); }}///<summary>//Motherboard information///</summary> public void Mainboardinfo () {try { ManagementClass mc = new MaNagementclass (WMIPath.Win32_BaseBoard.ToString ()); Managementobjectcollection MOC = MC. GetInstances (); foreach (ManagementObject mo in MoC) {Console.WriteLine ("Motherboard ID:" + mo.) properties["SerialNumber"]. Value); Console.WriteLine ("Manufacturer:" + mo.) properties["Manufacturer"]. Value); Console.WriteLine ("Model:" + mo.) properties["Product"]. Value); Console.WriteLine ("Version:" + mo.) properties["Version"]. Value); }} catch {Console.WriteLine ("Erroe"); }}///<summary>//Hard drive information///</summary> public void Diskdriveinfo () {try { ManagementClass mc = new ManagementClass (WMIPath.Win32_DiskDrive.ToString ()); Managementobjectcollection MOC = MC. GetInstances (); foreach (ManagementObject mo in MoC) {Console.WriteLine ("Hard disk SN:" + mo.) properties["SerialNumber"]. Value); Console.WriteLine ("Model:" + mo.) properties["Model"]. Value); Console.WriteLine ("Size:" + convert.todouble (mo. properties["Size"]. Value)/(1024 * 1024 * 1024)); }} catch {Console.WriteLine ("Erroe"); }}///<summary>///network connection information///</summary> public void Networkinfo () {try { ManagementClass mc = new ManagementClass (WMIPath.Win32_NetworkAdapterConfiguration.ToString ()); Managementobjectcollection MOC = MC. GetInstances (); foreach (ManagementObject mo in MoC) {Console.WriteLine ("MAC Address:" + mo. properties["MACAddress"]. Value); Console.WriteLine ("IP address:" + mo.) properties["IPAddress"]. Value); }} catch {Console.WriteLine ("Erroe"); }}///<summary>//operating System Information///</summary> public void OsInfo () {try {Ma} Nagementclass mc = new ManagementClass (WMIPath.Win32_OperatingSystem.ToString ()); Managementobjectcollection MOC = MC. GetInstances (); foreach (ManagementObject mo in MoC) {Console.WriteLine ("Operating system:" + mo. properties["Name"]. Value); Console.WriteLine ("Version:" + mo.) properties["Version"]. Value); Console.WriteLine ("System directory:" + mo.) properties["Systemdirectory"]. Value); }} catch {Console.WriteLine ("Erroe"); } } }}