1. 程式人生 > >C#生成唯一機器標識碼

C#生成唯一機器標識碼

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" } }