WMI获取硬件信息封装函数方法(联想台式机出厂编号 CPUID BIOS序列号 硬盘信息 显卡信息 MAC地址)

今天玩了一把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 videoId()
         {
            return identifier("Win32_VideoController", "DriverVersion")
                     + identifier("Win32_VideoController", "Name");
        }

获取网卡MAC地址信息:

代码如下:

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

(0)

相关推荐

  • iOS获取手机ip地址代码

    本文实例为大家分享了iOS获取手机ip地址的具体代码,供大家参考,具体内容如下 #import <ifaddrs.h> #import <arpa/inet.h> // Get IP Address - (NSString *)getIPAddress { NSString *address = @"error"; struct ifaddrs *interfaces = NULL; struct ifaddrs *temp_addr = NULL; int s

  • iOS将地址解析成经纬度的方法

    本文实例为大家分享了iOS将地址解析成经纬度的具体代码,供大家参考,具体内容如下 一.工程图 二.代码 ViewController.h #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import <CoreLocation/CLLocationManagerDelegate.h> @interface ViewController : UIViewController <CLLoca

  • iOS如何获取手机的Mac地址

    首先说明下,下面两种方法均可以获得手机的mac地址,但是有个限制,是在iOS7以下才可以获得.iOS7以后苹果对于sysctl和ioctl进行了技术处理,MAC地址返回的都是02:00:00:00:00:00. 官方文档上这样写的: "Twolow-level networking APIs that used to return a MAC address now return thefixed value 02:00:00:00:00:00. The APIs in question are

  • iOS开发中不合法的网络请求地址如何解决

    NSString *const kWebsite = @http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fr=&sf=1&fmq=1459502303089_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&

  • iOS获取当前连接的WiFi以及IP地址

    导入头文件 #import <ifaddrs.h> #import <arpa/inet.h> #import <SystemConfiguration/CaptiveNetwork.h> 核心代码: + (nullable NSString*)getCurrentLocalIP { NSString *address = nil; struct ifaddrs *interfaces = NULL; struct ifaddrs *temp_addr = NULL;

  • WMI获取硬件信息封装函数方法(联想台式机出厂编号 CPUID BIOS序列号 硬盘信息 显卡信息 MAC地址)

    今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都是可以提取出来的,就自己把那些公共部分提出出来,以后如果要获取某部分的硬件信息就不用写一个一个的函数,比如获取MAC地址就写一个获取MAC地址的函数,获取CPU 信息就写一个获取CPU信息的函数,太麻烦了 如下是函数代码: 复制代码 代码如下: private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)      

  • C# 获取硬件参数的实现方法

    C# 获取硬件参数的实现方法 示例代码: private static string GetIdentifier(string wmiClass, string wmiProperty, string wmiMustBeTrue) { string result = ""; System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass); System.Management.M

  • layui.use模块外部使用其内部定义的js封装函数方法

    用途:常用于监听输入框(其内部不提供监听函数). 用法:需要在 use 中定义 window 函数供外部引用. // 调用成功 <div class="layui-form-item " > <label class="layui-form-label">原密码</label> <div class="layui-input-block"> <input type="text&quo

  • 详解Linux系统中网卡MAC地址克隆方法

    怎么临时性地改变 MAC 地址? 你可以在 Linux 运行的时候改变 MAC 地址.需要注意的是当 MAC 地址转换的那一会时间,你的网络会掉线.当电脑重启时 MAC 地址又会变回原来的.下面介绍几种方法来改变你的 MAC 地址. 方法一:iproute2 $sudo ip link set dev eth0 down $sudo ip link set dev eth0 address 00:00:00:00:00:01 $sudo ip link set dev eth0 up 方法二:m

  • VB中使用WMI获取系统硬件和软件有关信息

    WMI是英文Windows Management Instrumentation的简写,它的功能主要是:访问本地主机的一些信息和服务,可以管理远程计算机(当然你必须要拥有足够的权限),比如:重启,关机,关闭进程,创建进程等. 当然此文是适用于vbscript 微软官方的资料: 实例如下: 用WMI,先工程-引用 Microsoft WMI Scripting V1.1 Library 获取显卡/声卡/内存/操作系统的信息 声卡信息 Private Sub wmiSoundDeviceInfo()

  • 纯批处理获取硬件信息的代码

    先声明:我私下会不断的更新代码,只有大幅度更新才会上传到这里(目前核心代码基本完善)! 兼容XP Win7 Win8 win10 本程序特性: 1.运行环境判断,若自身被修改则自动闪退:若PE环境则提示并指引退出:若虚拟机环境则提示信息获取可能不准:若非管理员权限也会截取并提示. 2.关于硬盘.内存容量的计算方面支持 字节 KB MB GB TB PB 3.由于有些电脑多网卡.显卡.声卡,此程序只获取正在使用的相关信息 4.硬盘温度,使用时间,通电次数纯批处理实现!(原创代码,转载请注明出处!)

  • Js 获取、判断浏览器版本信息的简单方法

    Navigator 对象包含有关浏览器的信息: •appCodeName -- 浏览器代码名的字符串表示 •appName -- 官方浏览器名的字符串表示 •appVersion -- 浏览器版本信息的字符串表示 •cookieEnabled -- 如果启用cookie返回true,否则返回false •javaEnabled -- 如果启用java返回true,否则返回false •platform -- 浏览器所在计算机平台的字符串表示 •plugins -- 安装在浏览器中的插件数组 •t

  • python执行shell获取硬件参数写入mysql的方法

    本文实例讲述了python执行shell获取硬件参数写入mysql的方法.分享给大家供大家参考.具体分析如下: 最近要获取服务器各种参数,包括cpu.内存.磁盘.型号等信息.试用了Hyperic HQ.Nagios和Snmp,它们功能都挺强大的,但是于需求不是太符,亦或者太heavy. 于是乎想到用python执行shell获取这些信息,python执行shell脚本有以下三种方法: 1. os.system() 复制代码 代码如下: os.system('ls') #返回结果0或者1,不能得到

  • 深入浅析Python获取对象信息的函数type()、isinstance()、dir()

    type()函数: 使用type()函数可以判断对象的类型,如果一个变量指向了函数或类,也可以用type判断. 如: class Student(object): name = 'Student' a = Student() print(type(123)) print(type('abc')) print(type(None)) print(type(abs)) print(type(a)) 运行截图如下: 可以看到返回的是对象的类型. 我们可以在if语句中判断比较两个变量的type类型是否相

  • Python运维之获取系统CPU信息的实现方法

    使用Python进行运维工作的时候有时候需要获取CPU的信息,这在psutil模块库的帮助下非常容易实现. 常见的CPU信息有以下几种: 1,用户时间以及百分比: 2,系统时间以及百分比: 3,空闲时间以及百分比: 4,CPU的硬件信息: 前3个中的时间可以采用cpu_times方法获取,百分比可以使用cpu_times_pcercent获得. 简单的示范如下: In [9]: importpsutil In [10]:psutil.cpu_times() Out[10]: scputimes(

随机推荐