Csharp/C#教程:C#编程获取客户端计算机硬件及系统信息功能示例分享

本文实例讲述了C#编程获取客户端计算机硬件及系统信息功能。分享给大家供大家参考,具体如下:

这里使用C#获取客户端计算机硬件及系统信息,包括CPU、硬盘、IP、MAC地址、操作系统等。

1、项目引用System.Management库。

2、创建HardwareHandler.cs类文件

usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Management; namespaceMyStudy.Utility { ///<summary> ///计算机硬件处理类 ///</summary> publicclassHardwareHandler { publicenumWMIPath { //硬件 Win32_Processor,//CPU处理器 Win32_PhysicalMemory,//物理内存条 Win32_Keyboard,//键盘 Win32_PointingDevice,//点输入设备,包括鼠标。 Win32_FloppyDrive,//软盘驱动器 Win32_DiskDrive,//硬盘驱动器 Win32_CDROMDrive,//光盘驱动器 Win32_BaseBoard,//主板 Win32_BIOS,//BIOS芯片 Win32_ParallelPort,//并口 Win32_SerialPort,//串口 Win32_SerialPortConfiguration,//串口配置 Win32_SoundDevice,//多媒体设置,一般指声卡。 Win32_SystemSlot,//主板插槽(ISA&PCI&AGP) Win32_USBController,//USB控制器 Win32_NetworkAdapter,//网络适配器 Win32_NetworkAdapterConfiguration,//网络适配器设置 Win32_Printer,//打印机 Win32_PrinterConfiguration,//打印机设置 Win32_PrintJob,//打印机任务 Win32_TCPIPPrinterPort,//打印机端口 Win32_POTSModem,//MODEM Win32_POTSModemToSerialPort,//MODEM端口 Win32_DesktopMonitor,//显示器 Win32_DisplayConfiguration,//显卡 Win32_DisplayControllerConfiguration,//显卡设置 Win32_VideoController,//显卡细节。 Win32_VideoSettings,//显卡支持的显示模式。 //操作系统 Win32_TimeZone,//时区 Win32_SystemDriver,//驱动程序 Win32_DiskPartition,//磁盘分区 Win32_LogicalDisk,//逻辑磁盘 Win32_LogicalDiskToPartition,//逻辑磁盘所在分区及始末位置。 Win32_LogicalMemoryConfiguration,//逻辑内存配置 Win32_PageFile,//系统页文件信息 Win32_PageFileSetting,//页文件设置 Win32_BootConfiguration,//系统启动配置 Win32_ComputerSystem,//计算机信息简要 Win32_OperatingSystem,//操作系统信息 Win32_StartupCommand,//系统自动启动程序 Win32_Service,//系统安装的服务 Win32_Group,//系统管理组 Win32_GroupUser,//系统组帐号 Win32_UserAccount,//用户帐号 Win32_Process,//系统进程 Win32_Thread,//系统线程 Win32_Share,//共享 Win32_NetworkClient,//已安装的网络客户端 Win32_NetworkProtocol,//已安装的网络协议 } ///<summary> ///Cpu信息 ///</summary> ///<returns></returns> publicvoidCpuInfo() { try { ManagementClassmc=newManagementClass(WMIPath.Win32_Processor.ToString()); ManagementObjectCollectionmoc=mc.GetInstances(); foreach(ManagementObjectmoinmoc) { Console.WriteLine("CPU编号:"+mo.Properties["ProcessorId"].Value); Console.WriteLine("CPU型号:"+mo.Properties["Name"].Value); Console.WriteLine("CPU状态:"+mo.Properties["Status"].Value); Console.WriteLine("主机名称:"+mo.Properties["SystemName"].Value); } } catch { Console.WriteLine("Erroe"); } } ///<summary> ///主板信息 ///</summary> publicvoidMainBoardInfo() { try { ManagementClassmc=newManagementClass(WMIPath.Win32_BaseBoard.ToString()); ManagementObjectCollectionmoc=mc.GetInstances(); foreach(ManagementObjectmoinmoc) { Console.WriteLine("主板ID:"+mo.Properties["SerialNumber"].Value); Console.WriteLine("制造商:"+mo.Properties["Manufacturer"].Value); Console.WriteLine("型号:"+mo.Properties["Product"].Value); Console.WriteLine("版本:"+mo.Properties["Version"].Value); } } catch { Console.WriteLine("Erroe"); } } ///<summary> ///硬盘信息 ///</summary> publicvoidDiskDriveInfo() { try { ManagementClassmc=newManagementClass(WMIPath.Win32_DiskDrive.ToString()); ManagementObjectCollectionmoc=mc.GetInstances(); foreach(ManagementObjectmoinmoc) { Console.WriteLine("硬盘SN:"+mo.Properties["SerialNumber"].Value); Console.WriteLine("型号:"+mo.Properties["Model"].Value); Console.WriteLine("大小:"+Convert.ToDouble(mo.Properties["Size"].Value)/(1024*1024*1024)); } } catch { Console.WriteLine("Erroe"); } } ///<summary> ///网络连接信息 ///</summary> publicvoidNetworkInfo() { try { ManagementClassmc=newManagementClass(WMIPath.Win32_NetworkAdapterConfiguration.ToString()); ManagementObjectCollectionmoc=mc.GetInstances(); foreach(ManagementObjectmoinmoc) { Console.WriteLine("MAC地址:"+mo.Properties["MACAddress"].Value); Console.WriteLine("IP地址:"+mo.Properties["IPAddress"].Value); } } catch { Console.WriteLine("Erroe"); } } ///<summary> ///操作系统信息 ///</summary> publicvoidOsInfo() { try { ManagementClassmc=newManagementClass(WMIPath.Win32_OperatingSystem.ToString()); ManagementObjectCollectionmoc=mc.GetInstances(); foreach(ManagementObjectmoinmoc) { Console.WriteLine("操作系统:"+mo.Properties["Name"].Value); Console.WriteLine("版本:"+mo.Properties["Version"].Value); Console.WriteLine("系统目录:"+mo.Properties["SystemDirectory"].Value); } } catch { Console.WriteLine("Erroe"); } } } }

更多关于C#相关内容感兴趣的读者可查看本站专题:《C#程序设计之线程使用技巧上述就是C#学习教程:C#编程获取客户端计算机硬件及系统信息功能示例分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/907672.html

(0)
上一篇 2021年10月24日
下一篇 2021年10月24日

精彩推荐