最近學習過程中,想到提取系統硬體資訊做一些驗證,故而對網上提到的利用.NET System.Management類擷取硬體資訊做了進一步的學習、驗證。驗證是分別在4台電腦,XP SP3系統中進行,特將驗證過程記錄於此。
說明:
電腦1(聯想品牌電腦);
電腦2(HP品牌電腦);
電腦3(聯想品牌電腦);
電腦4(相容機);
擷取CPU編號:
view plaincopy to clipboardprint?
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null ;
foreach( ManagementObject mo in moc )
{
strID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
textBox1.Text += "CPU ID:" + strID;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null ;
foreach( ManagementObject mo in moc )
{
strID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
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 )
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
textBox1.Text += "主板 ID:" + strID;
ManagementClass mc = new ManagementClass("Win32_BaseBoard");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null ;
foreach( ManagementObject mo in moc )
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
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 )
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
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 )
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
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 )
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
textBox1.Text += "BIOS ID:" + strID;
ManagementClass mc = new ManagementClass("Win32_BIOS");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null ;
foreach( ManagementObject mo in moc )
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
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============CUP資訊===========";
foreach (PropertyData pd in mo.Properties)
{
textBox1.Text += "\r\n" + pd.Name + "\t";
if (pd.Value != null)
{
textBox1.Text += pd.Value.ToString();
}
}
textBox1.Text += "\r\n\r\n=======================";
}