C 獲取硬體資訊 CPU MAC等

2021-05-23 07:28:29 字數 2091 閱讀 1463

using system.management;

//win32_networkadapterconfiguration是wmi資料庫中用來存放網路裝置的資訊表

managementobjectsearcher query = new managementobjectsearcher("select * from win32_networkadapterconfiguration where ipenabled='true'");

//managementobjectcollection物件用來存放查詢結果

managementobjectcollection querycollection = query.get();

foreach (managementobject mo in querycollection)

", mo["description"]);

console.writeline("mac address:", mo["macaddress"]);

//addresses, subnets和 defaultgateways 值都是可以包含多個值得陣列.

//為了適應這種情況,為了適應這種情況,使用者必須把結果分配到乙個字串陣列,

//並再一次用foreach語句通過該字串陣列

string addresses = (string)mo["ipaddress"];

string subnets = (string)mo["ipsubnet"];

string defaultgateways = (string)mo["defaultipgateway"];

//任何乙個介面都可能有多個ip位址

}有關win32_share詳細類資訊可參考msdn:http://msdn.microsoft.com/en-us/library/aa394435(vs.85).aspx

c 獲取硬體資訊

using system using system.runtime.interopservices using system.management namespace hardware 取cpu編號 public string getcpuid return strcpuid catch end m...

c 獲取硬體資訊

using system using system.runtime.interopservices using system.management namespace hardware 取cpu編號 public string getcpuid return strcpuid catch end m...

C 獲取硬體資訊

using system using system.net using system.runtime.interopservices using system.management 需要在解決方案中引用system.management.dll檔案 獲取機器名 public string getho...