WMI獲取硬件信息封裝函數(shù)方法(聯(lián)想臺(tái)式機(jī)出廠編號 CPUID BIOS序列號 硬盤信息 顯卡信息 MAC地址)
今天玩了一把WMI,查詢了一下電腦的硬件信息,感覺很多代碼都是可以提取出來的,就自己把那些公共部分提出出來,以后如果要獲取某部分的硬件信息就不用寫一個(gè)一個(gè)的函數(shù),比如獲取MAC地址就寫一個(gè)獲取MAC地址的函數(shù),獲取CPU 信息就寫一個(gè)獲取CPU信息的函數(shù),太麻煩了
如下是函數(shù)代碼:
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"); //最大時(shí)鐘頻率
return retVal;
}
獲取BIOS信息,其中BIOS序列號就是聯(lián)想臺(tái)式機(jī)的出廠編號,我看聯(lián)想的保修頁面里的自動(dòng)獲取主機(jī)編號應(yīng)該也是調(diào)用這個(gè)"Win32_BIOS"的 "SerialNumber
報(bào)修頁面網(wǎng)址: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"); //扇區(qū)頭
}
獲取顯卡信息:
private static string videoId()
{
return identifier("Win32_VideoController", "DriverVersion")
+ identifier("Win32_VideoController", "Name");
}
獲取網(wǎng)卡MAC地址信息:
private static string macId()
{
return identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled");
}
- iOS如何獲取手機(jī)的Mac地址
- iOS、Mac OS X系統(tǒng)中編程實(shí)現(xiàn)漢字轉(zhuǎn)拼音的方法(超級簡單)
- Nagios遠(yuǎn)程監(jiān)控安裝與配置詳解圖文
- iOS10 適配遠(yuǎn)程推送功能實(shí)現(xiàn)代碼
- iOS實(shí)現(xiàn)遠(yuǎn)程推送原理及過程
- iOS實(shí)現(xiàn)播放遠(yuǎn)程網(wǎng)絡(luò)音樂的核心技術(shù)點(diǎn)總結(jié)
- iOS10最新實(shí)現(xiàn)遠(yuǎn)程通知的開發(fā)教程詳解
- iOS開發(fā)之運(yùn)動(dòng)事件和遠(yuǎn)程控制
- iOS Remote Notification遠(yuǎn)程消息推送處理
- iOS-Mac遠(yuǎn)程連接控制Window
相關(guān)文章
C#如何讀取Txt大數(shù)據(jù)并更新到數(shù)據(jù)庫詳解
這篇文章主要給大家介紹了關(guān)于C#如何讀取Txt大數(shù)據(jù)并更新到數(shù)據(jù)庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08C#的FileInfo類實(shí)現(xiàn)文件操作實(shí)例
這篇文章主要介紹了C#的FileInfo類實(shí)現(xiàn)文件操作實(shí)例,比較實(shí)用的功能,需要的朋友可以參考下2014-07-07C#實(shí)現(xiàn)一個(gè)Word保護(hù)性模板文件
這篇文章主要為大家詳細(xì)介紹了C#如何實(shí)現(xiàn)一個(gè)Word保護(hù)性模板文件,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的小伙伴可以參考一下2024-01-01Unity UI實(shí)現(xiàn)循環(huán)播放序列圖
這篇文章主要為大家詳細(xì)介紹了Unity UI實(shí)現(xiàn)循環(huán)播放序列圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08C# XML與Json之間相互轉(zhuǎn)換實(shí)例詳解
這篇文章主要介紹了C# XML與Json之間相互轉(zhuǎn)換實(shí)例詳解,大家參考使用吧2013-11-11