這篇文章主要介紹了C#編程獲取各種電腦硬體資訊的方法,結合實例形式分析了C#獲取電腦CPU、主機板、硬碟、BIOS編號等資訊的相關操作技巧與注意事項,需要的朋友可以參考下
本文實例講述了C#程式設計獲取各種電腦硬體資訊的方法。分享給大家供大家參考,具體如下:
取得CPU編號:
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
取得主機板編號:
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:
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編號:
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:
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======================="; }
以上是C#程式設計如何取得電腦硬體資訊的方法?的詳細內容。更多資訊請關注PHP中文網其他相關文章!