What is a good unique PC identifier?

后端 未结 13 2009
深忆病人
深忆病人 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:48

    The real answer to that question: There is no such thing.

    There are several "close enough" solutions, but each one of those has it's own limitation.

    All the hardware IDs - Hardware changes. And, in many cases you can change those identifiers (For example, MAC spoofing).

    The SID, as I've already commented, Is not that good as well, because the SID won't change if the computer was installed from an image. The SID is generated by windows installation, if windows wasn't installed, but copied from an image, the SID won't change (although it is common to regenerate it because of a myth about "security risk" - you can't count on that).

    Computer name - Well, as mentioned, They suppose to be unique, but it's not enforced in any way.

    Another solution you can implement is to generate you own unique identifier and store it locally (assuming you can do such thing). Again, this solution won't work if your computer was imaged with your application.

    The best solution for you really depends on what you are trying to accomplish. I had the same problem with a quite large network, and the best solution in my case was the computer's name. If you are absolutely sure that your process won't be imaged, I would generate a unique identifier using Guid because it will probably be the safest.

    0 讨论(0)
  • 2020-11-27 11:49

    I don't think it's possible to have two PC's with the same name on the same domain. Have you tried capturing the domain name?

    0 讨论(0)
  • 2020-11-27 11:51

    Take a look here: Getting Service Tag from Dell Machine using .net?

    You could snatch some unique data from the registry.

    0 讨论(0)
  • 2020-11-27 11:52

    Take three identifiers that are semi-unique and semi-constant. Use the rule that 2 out of 3 is sufficient for a positive identification. Update the registered data for the 1 out of 3 that is occasionally wrong.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-27 11:56

    There is a sample code with complete notes in this link for getting CPU and HD Drive ID: http://www.vcskicks.com/hardware_id.php

    add this dll to refrences

     System.Management.dll
    

    for CPU ID:

    string cpuInfo = string.Empty;
    ManagementClass mc = new ManagementClass("win32_processor");
    ManagementObjectCollection moc = mc.GetInstances();
    
    foreach (ManagementObject mo in moc)
    {
         if (cpuInfo == "")
         {
              //Get only the first CPU's ID
              cpuInfo = mo.Properties["processorID"].Value.ToString();
              break;
         }
    }
    return cpuInfo;
    

    and for Hard Drive ID (Volume Serial):

    ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
    dsk.Get();
    string volumeSerial = dsk["VolumeSerialNumber"].ToString();
    
    0 讨论(0)
提交回复
热议问题