原文:WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法

今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都是可以提取出来的,就自己把那些公共部分提出出来,以后如果要获取

某部分的硬件信息就不用写一个一个的函数,比如获取MAC地址就写一个获取MAC地址的函数,获取CPU 信息就写一个获取CPU信息的

函数,太麻烦了

如下是函数代码:

         private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
if (mo[wmiMustBeTrue].ToString() == "True")
{
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
} }
}
return result;
} private static string identifier(string wmiClass, string wmiProperty)
{
string result = "";
System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
} }
return result;
}

获取CPUID

         private static string cpuId()
{
string retVal = identifier("Win32_Processor", "UniqueId"); //CPUID
retVal += identifier("Win32_Processor", "ProcessorId");
retVal += identifier("Win32_Processor", "Name"); //处理器名称
retVal += identifier("Win32_Processor", "Manufacturer"); //处理器制造商
retVal +=identifier("Win32_Processor", "MaxClockSpeed"); //最大时钟频率
return retVal;
}

获取BIOS信息,其中BIOS序列号就是联想台式机的出厂编号,我看联想的保修页面里的自动获取主机编号应该也是调用

这个"Win32_BIOS"的 "SerialNumber

报修页面网址:http://support1.lenovo.com.cn/lenovo/wsi/wsbx/lenovo/#minarepairInfo

         //BIOS信息
private static string biosId()
{
return identifier("Win32_BIOS", "Manufacturer") //BIOS制造商名称
+ identifier("Win32_BIOS", "SMBIOSBIOSVersion") //
+ identifier("Win32_BIOS", "IdentificationCode") //
+ identifier("Win32_BIOS", "SerialNumber") //BIOS序列号
+ identifier("Win32_BIOS", "ReleaseDate") //出厂日期
+ identifier("Win32_BIOS", "Version"); //版本号
}

获取硬盘信息:

         private static string diskId()
{
return identifier("Win32_DiskDrive", "Model") //模式
+ identifier("Win32_DiskDrive", "Manufacturer") //制造商
+ identifier("Win32_DiskDrive", "Signature") //签名
+ identifier("Win32_DiskDrive", "TotalHeads"); //扇区头
}

获取主板信息:

         private static string baseId()
{
return identifier("Win32_BaseBoard", "Model")
+ identifier("Win32_BaseBoard", "Manufacturer")
+ identifier("Win32_BaseBoard", "Name")
+ identifier("Win32_BaseBoard", "SerialNumber");
}

获取显卡信息:

         private static string videoId()
{
return identifier("Win32_VideoController", "DriverVersion")
+ identifier("Win32_VideoController", "Name");
}

获取网卡MAC地址信息:

         private static string macId()
{
return identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
}

如有什么不对的地方,欢迎大家拍砖!!

WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号方法的更多相关文章

  1. linux下dmidecode命令获取硬件信息

    linux下dmidecode命令获取硬件信息 2 A+ 所属分类:Linux 运维工具 dmidecode在 Linux 系统下获取有关硬件方面的信息.dmidecode 遵循 SMBIOS/DMI ...

  2. nginx获取头部信息带下划线,获取不到解决方案

    nginx获取头部信息带下划线,获取不到解决方案 解决方案: 修改配置文件,进行添加信息如下: underscores_in_headers on; 然后进行重新加载: [root@qa-web co ...

  3. C#通过WMI获取硬件信息

    有时候需要得到硬件信息绑定用户登录 代码如下: private string GetProcessSerialNumber() { try { ManagementObjectCollection P ...

  4. 获取硬件信息的delphi源码CPUID、操作系统、Mac物理地址、计算机名称、IP地址、用户名

    {-----------------------------------------------------------------------------作者:sushengmiyan 2013.0 ...

  5. C#获取硬件信息

    //硬件信息 public class GF_Hardware { /// <summary> /// cpu序列号 /// </summary> /// <return ...

  6. ansible facts 获取硬件信息

    facts 指的是 ansible_facts 变量,ansible 中使用 setup 模块来获取,包含系统的大部分基础硬件信息, [root@10_1_162_39 host_vars]# ll ...

  7. Web网站中利用JavaScript中ActiveXObject对象获取硬件信息(显示器数量、分辨率)从而进行单双屏跳转

    前言:最近这两天工作上,要实现一个功能,在好友阿聪的帮助下,算是比较好的解决了这个需求. B/S的Web网站,需要实现点击按钮时,根据客户端连接的显示屏(监视器)数量进行,单双屏跳转显示新页面. 由于 ...

  8. Powershell获取硬件信息

    1.获取系统的BIOS的信息: Get-WMIObject -Class Win32_BIOS 2.获取内存信息: Get-WMIObject -Class Win32_PhysicalMemory ...

  9. PHP通过ZABBIX API获取主机信息 VS 直接从数据库获取主机信息

    最近项目需要获取linux主机的一些信息,如CPU使用率,内存使用情况等.由于我们本身就装了zabbix系统,所以我只用知道如何获取信息即可,总结有两种方法可以获取. 一.通过ZABBIX API获取 ...

随机推荐

  1. Jobbox.io(职位盒子): 新兴的面向技术人才的职场招聘众推平台

    人才招聘市场一个主要问题在于猎头中介费昂贵.这对于大公司而言,或可接受. 但对于海量小微企业而言招聘成本和效率之间的平衡是非常大的一个问题. 现在产品猎场(Product Hunt)上出现了一些新的招 ...

  2. POJ1505&amp;&amp;UVa714 Copying Books(DP)

    Copying Books Time Limit: 3000MS Memory Limit: 10000K Total Submissions: 7109 Accepted: 2221 Descrip ...

  3. libuv 与 libev 的对比

    libuv 与 libev 的对比 libuv 与 libev 的对比 05 January 2013 libuv 和 libev ,两个名字相当相近的 I/O Library,最近有幸用两个 Lib ...

  4. hdu1042(大数模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 在网上找了个大数模板方便以后用得到. #include<iostream> #inc ...

  5. UVA 11090 - Going in Cycle!!(Bellman-Ford)

    UVA 11090 - Going in Cycle!! option=com_onlinejudge&Itemid=8&page=show_problem&category= ...

  6. linux下golang

    linux下golang的配置 linux下golang的配置 之前开发golang一直在windows下,今天在linux下试了一下 ,遇到一些梗,比如go 找不到 sync包.花了一小时全部解决, ...

  7. 最牛B的编程套路

    最近,我大量阅读了Steve Yegge的文章.其中有一篇叫“Practicing Programming”(练习编程),写成于2005年,读后令我惊讶不已: 与你所相信的恰恰相反,单纯地每天埋头于工 ...

  8. Instruments的使用 逻辑查错,内存泄漏分析等工具集

    原创文章,转载请注明 XCode 开发后期,要对代码进行改进和优化,查内存泄漏是其中一项重要工作,今天下午偷了点时间,把前段时间的代码稍微整理了一下,顺带用了下这个工具,还真发现了些问题.这里记录一下 ...

  9. 微端 代码project as air 分享

    分享 ^_^ 1. 使用 air , as . 2. 微端下载和更新技术 成功上线棋牌游戏.它可用于传统的游戏开发. 地址: http://download.csdn.net/detail/stone ...

  10. c#开发微信公众平台

    之前帮公司开发过微信公众账号,今天特别将过程再回顾记录下来. 1.URL配置 启用开发模式需要先成为开发者,而且编辑模式和开发模式只能选择一个,进入微信公众平台-开发模式,如下: 从上面可以看出,点击 ...