a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

WMI獲取硬件信息封裝函數方法(聯想臺式機出廠編號 CPUID BIOS序列號 硬盤信息 顯卡信息 MAC地址)

2020-01-24 03:03:48
字體:
來源:轉載
供稿:網友

今天玩了一把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");
        }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中文字幕免费在线观看视频 | 日本污视频在线观看 | 九色 在线 | 97久久精品午夜一区二区 | 亚洲精品免费在线观看 | 精品无码久久久久国产 | 久久精品国产99 | 四虎com| 国精产品一区一区三区免费完 | 福利视频一区 | 亚洲最黄视频 | 久久综合99re88久久爱 | 亚洲国产精品精华液com | 久久久九九 | 黄瓜av| 天天噜天天干 | 一级黄色片子免费看 | 精品欧美一区二区三区久久久 | 欧美色图首页 | 免费不卡一区 | 国产二区三区 | 九九热在线视频观看这里只有精品 | 亚洲国产精品久久久久 | 黄色视屏免费观看 | 色婷婷狠狠| 绯色av一区二区三区在线高清 | 日韩激情欧美 | 成人影院av | 久久久精品网站 | www.欧美日韩 | 国变精品美女久久久久av爽 | 欧美一区三区 | 欧美色综合一区二区三区 | 欧美一级艳片视频免费观看 | 黄a一级| 热久久久 | 精品久久久久香蕉网 | 欧美午夜精品久久久久久浪潮 | yy6080久久伦理一区二区 | 草草网 | 视频一区二区在线 |