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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-20 我要评论
想了解WMI获取硬件信息封装函数方法(联想台式机出厂编号 CPUID BIOS序列号 硬盘信息 显卡信息 MAC地址)的相关内容吗,在本文为您仔细讲解WMI 获取硬件信息的封装函数与获取联想台式机的出厂编号 方法的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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");
        }

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们