What is a good unique PC identifier?

后端 未结 13 2072
深忆病人
深忆病人 2020-11-27 10:59

I\'ve been looking at the code in this tutorial, and I found that it uses My.Computer.Name to save settings that shouldn\'t roam between computers. It\'s entire

13条回答
  •  温柔的废话
    2020-11-27 11:54

    We use a combination of the ProcessorID from Win32_processor and the UUID from Win32_ComputerSystemProduct:

    ManagementObjectCollection mbsList = null;
    ManagementObjectSearcher mos = new ManagementObjectSearcher("Select ProcessorID From Win32_processor");
    mbsList = mos.Get();
    string processorId = string.Empty;
    foreach (ManagementBaseObject mo in mbsList)
    {
        processorId = mo["ProcessorID"] as string;
    }
    
    mos = new ManagementObjectSearcher("SELECT UUID FROM Win32_ComputerSystemProduct");
    mbsList = mos.Get();
    string systemId = string.Empty;
    foreach (ManagementBaseObject mo in mbsList)
    {
        systemId = mo["UUID"] as string;
    }
    
    var compIdStr = $"{processorId}{systemId}";
    

    Previously, we used a combination: processor ID ("Select ProcessorID From Win32_processor") and the motherboard serial number ("SELECT SerialNumber FROM Win32_BaseBoard"), but then we found out that the serial number of the motherboard may not be filled in, or it may be filled in with uniform values:

    • To be filled by O.E.M.
    • None
    • Default string

    Therefore, it is worth considering this situation.

    Also keep in mind that the ProcessorID number may be the same on different computers.

提交回复
热议问题