What is a good unique PC identifier?

后端 未结 13 2010
深忆病人
深忆病人 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 12:03

    Here is a way to uniquely identify a computer. Using System.Management to get Win32_BIOS, you can get unique values from your machine's BIOS.

    See: Win32_BIOS class, http://msdn.microsoft.com/en-us/library/aa394077.aspx

    using System.Management;
    
    string UniqueMachineId()
    {
        StringBuilder builder = new StringBuilder();
    
        String query = "SELECT * FROM Win32_BIOS";
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
        //  This should only find one
        foreach (ManagementObject item in searcher.Get())
        {
            Object obj = item["Manufacturer"];
            builder.Append(Convert.ToString(obj));
            builder.Append(':');
            obj = item["SerialNumber"];
            builder.Append(Convert.ToString(obj));
        }
    
    return builder.ToString();
    }
    

    With similar logic, you can also step through "Win32_DiskDrive"; http://msdn.microsoft.com/en-us/library/aa394132.aspx; and get "SerialNumber" for each physical drive. In this case, the

        foreach (ManagementObject item in searcher.Get())
    

    should find multiple items

    0 讨论(0)
提交回复
热议问题