C 獲取電腦硬體資訊

2022-05-01 07:39:11 字數 3554 閱讀 5262

獲取cpu編號:

view plaincopy to clipboardprint?

managementclass mc = new managementclass("win32_processor"); 

managementobjectcollection moc = mc.getinstances(); 

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "cpu id:" + strid; 

managementclass mc = new managementclass("win32_processor");

managementobjectcollection moc = mc.getinstances();

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "cpu id:" + strid;

返回結果:

電腦1:cpu id:bfebfbff00000f27

電腦2:cpu id:bfebfbff00000f27

電腦3:cpu id:bfebfbff00000f29

電腦4:cpu id:bfebfbff00000f29

獲取主機板編號:

view plaincopy to clipboardprint?

managementclass mc = new managementclass("win32_baseboard"); 

managementobjectcollection moc = mc.getinstances(); 

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "主機板 id:" + strid; 

managementclass mc = new managementclass("win32_baseboard");

managementobjectcollection moc = mc.getinstances();

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "主機板 id:" + strid;

返回結果:

電腦1:主機板 id:

電腦2:主機板 id:cn24401483

電腦3:主機板 id:azf241001101

電腦4:主機板 id:

獲取硬碟編號:

view plaincopy to clipboardprint?

managementclass mc = new managementclass("win32_physicalmedia"); 

//網上有提到,用win32_diskdrive,但是用win32_diskdrive獲得的硬碟資訊中並不包含serialnumber屬性。 

managementobjectcollection moc = mc.getinstances(); 

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "硬碟 id:" + strid; 

managementclass mc = new managementclass("win32_physicalmedia");

//網上有提到,用win32_diskdrive,但是用win32_diskdrive獲得的硬碟資訊中並不包含serialnumber屬性。

managementobjectcollection moc = mc.getinstances();

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "硬碟 id:" + strid;

返回結果:

電腦1:硬碟 id:4833395344463658202020202020202020202020

電腦2:硬碟 id:wd-wmajd1092385

電腦3:硬碟 id:4a353756354d5939202020202020202020202020

電腦4:硬碟 id:0637j2fw508014

獲取bios編號:

view plaincopy to clipboardprint?

managementclass mc = new managementclass("win32_bios"); 

managementobjectcollection moc = mc.getinstances(); 

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "bios id:" + strid; 

managementclass mc = new managementclass("win32_bios");

managementobjectcollection moc = mc.getinstances();

string strid = null ; 

foreach( managementobject mo in moc ) 

textbox1.text += "bios id:" + strid;

返回結果:

電腦1:bios id: 

電腦2:bios id:cn24401483

電腦3:bios id:

電腦4:bios id:

總結:由以上各步看出,通過win32_processor獲取cpuid不正確,或者說win32_processor欄位就不包含cpu編號資訊。

通過win32_baseboard獲取主機板資訊,但不是所有的主機板都有編號,或者說不是能獲取所有系統主機板的編號。

通過win32_physicalmedia獲取硬碟編號應該沒有問題。但網上說可以通過win32_diskdrive獲取,其實所得資訊根本不包含serialnumber。

通過win32_bios獲取bios資訊,基本和獲取主機板資訊差不多。就是說:不是所有的主機板bios資訊都有編號。

另外,可以將通過以上各欄位所得資訊輸出,逐個檢視所有資訊 屬性和對應的值。**如下:

view plaincopy to clipboardprint?

managementclass mc = new managementclass("win32_processor"); 

managementobjectcollection moc = mc.getinstances(); 

foreach( managementobject mo in moc )  } 

textbox1.text += "\r\n\r\n**********============="; 

獲取電腦硬體資訊

csharp csharp csharp csharp using system using system.collections using system.management namespace hardwareinfos public static hashtable getallinfos ...

C 獲取電腦硬體配置資訊

using system using system.management using system.collections using system.collections.specialized using system.text namespace rainsoft.management end...

vbs wmi獲取電腦硬體資訊例項

set wmi getobject winmgmts 程式設計客棧 setoepgjpyab board wmi.instancesof win32 baseboard for each b in board msg 主機板 b.manufacturer vbtab b.product vbtab ...