C#生成唯一機器標識碼
阿新 • • 發佈:2019-02-16
public static string getUniqueID(){
try{
ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
ManagementObjectCollection mbsList = mbs.Get();
string id = "";
foreach(ManagementObject mo in mbsList)
{
id = mo["ProcessorID" ].ToString();
}
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * From Win32_BaseBoard");
ManagementObjectCollection moc= mbs.Get();
string motherBoard = "";
foreach(ManagementObject mo in moc)
{
motherBoard = (string)mo["SerialNumber" ];
}
return id + motherBoard
}catch(Exception ex){
return "這裡是預設的id"
}
}