1. 專案請先加入參考 System.Management
2. 透過 ManagementObjectSearcher 查詢CPU serial number.
private void button2_Click(object sender, EventArgs e)
{
// 透過 ManagementObjectSearcher 類別用類似 SQL 的語法查詢
ManagementObjectSearcher wmiSearcher
= new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
int i = 0;
// 使用 ManagementObjectSearcher 的 Get 方法取得所有集合
foreach (ManagementObject obj in wmiSearcher.Get())
{
// 取得CPU 序號
//Console.WriteLine("CPU{0} ID:\t{1}", i++, obj["ProcessorId"].ToString());
CommonData.WriteMessage(CommonData.richtextbox, "CPU{0} ID:\t{1}-"+ (i++).ToString()+" - ", obj["ProcessorId"].ToString(), Color.Blue, Color.Green);
}
}
執行畫面
沒有留言:
張貼留言