-
c#获到电脑硬件配置信息
制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
usingSystem;
usingSystem.Management; usingSystem.Collections; usingSystem.Collections.Specialized; usingSystem.Text; namespaceRainsoft.Management { #regionWMIPath 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,//已安装的网络协议 } #endregion ///<summary> ///获取系统信息 ///</summary> ///<example> ///<code> ///WMIw=newWMI(WMIPath.Win32_NetworkAdapterConfiguration); ///for(inti=0;i<w.Count;i++) ///{ ///if((bool)w[i,"IPEnabled"]) ///{ ///Console.WriteLine("Caption:{0}",w[i,"Caption"]); ///Console.WriteLine("MACAddress:{0}",w[i,"MACAddress"]); ///} ///} ///</code> ///</example> publicsealedclassWMI { privateArrayListmocs; privateStringDictionarynames;//用来存储属性名,便于忽略大小写查询正确名称。 ///<summary> ///信息集合数量 ///</summary> publicintCount { get{returnmocs.Count;} } ///<summary> ///获取指定属性值,注意某些结果可能是数组。 ///</summary> publicobjectthis[intindex,stringpropertyName] { get { try { stringtrueName=names[propertyName.Trim()];//以此可不区分大小写获得正确的属性名称。 Hashtableh=(Hashtable)mocs[index]; returnh[trueName]; } catch { returnnull; } } } ///<summary> ///返回所有属性名称。 ///</summary> ///<paramname="index"></param> ///<returns></returns> publicstring[]PropertyNames(intindex) { try { Hashtableh=(Hashtable)mocs[index]; string[]result=newstring[h.Keys.Count]; h.Keys.CopyTo(result,0); Array.Sort(result); returnresult; } catch { returnnull; } } ///<summary> ///返回测试信息。 ///</summary> ///<returns></returns> publicstringTest() { try { StringBuilderresult=newStringBuilder(1000); for(inti=0;i<Count;i++) { intj=0; foreach(stringsinPropertyNames(i)) { result.Append(string.Format("{0}:{1}={2}n",++j,s,this[i,s])); if(this[i,s]isArray) { Arrayv1=this[i,s]asArray; for(intx=0;x<v1.Length;x++) { result.Append("t"+v1.GetValue(x)+"n"); } } } result.Append("======WMI=======n"); } returnresult.ToString(); } catch { returnstring.Empty; } } ///<summary> ///构造函数 ///</summary> ///<paramname="path"></param> publicWMI(stringpath) { names=newStringDictionary(); mocs=newArrayList(); try { ManagementClasscimobject=newManagementClass(path); ManagementObjectCollectionmoc=cimobject.GetInstances(); boolok=false; foreach(ManagementObjectmoinmoc) { Hashtableo=newHashtable(); mocs.Add(o); foreach(PropertyDatapinmo.Properties) { o.Add(p.Name,p.Value); if(!ok)names.Add(p.Name,p.Name); } ok=true; mo.Dispose(); } moc.Dispose(); } catch(Exceptione) { thrownewException(e.Message); } } ///<summary> ///构造函数 ///</summary> ///<paramname="path"></param> publicWMI(WMIPathpath):this(path.ToString()) { } } } |
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程
检测数据类型的四种方法
js中数组的方法,32种方法
前端操作方法
数据类型
window.localStorage.setItem 和 localStorage.setIte
如何完美解决前端数字计算精度丢失与数