What is a good unique PC identifier?

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

    In a managed network environment, the best, most reliable identifier might be the one you create, but there are some downsides.

    Some (many?) manufacturers provide a utility that allows you to set an asset tag that is stored in the firmware. This might be a bootable utility, or it might run within Windows, or it might even be built into the firmware setup. This "tag" is an arbitrary text string that you can set to whatever you want, and then read it back using WMI and the Win32_SystemEnclosure class...

    string[] selectedProperties = new string[] { "SMBIOSAssetTag" };
    ObjectQuery enclosureQuery = new SelectQuery("Win32_SystemEnclosure", null, selectedProperties);
    
    using (ManagementObjectSearcher enclosureSearcher = new ManagementObjectSearcher(enclosureQuery))
    using (ManagementObjectCollection enclosureCollection = enclosureSearcher.Get())
    {
        foreach (ManagementObject enclosure in enclosureCollection)
        {
            string assetTag = (string) enclosure.GetPropertyValue("SMBIOSAssetTag");
        }
    }
    

    Pros:

    • You can use whatever scheme you want (e.g. incorporating date, department, incrementing integers, GUIDs, etc.).
    • You can use one scheme for all machines regardless of their manufacturer, instead of having to handle manufacturer-specific schemes.
    • By allocating and tracking the identifiers yourself, you can guarantee that they are unique. Not relying on an identifier set by the manufacturer means there is no risk of duplicates within a manufacturer or between manufacturers.
    • The identifier is stored in the firmware — not on the hard drive — so it will survive reformatting, upgrades, etc. but also not be duplicated by backups/imaging/cloning.

    Cons:

    • You need to actually set the asset tag; they'll all be blank until you do so.
    • Setting a machine's asset tag may require physical access and a reboot.
    • Asset tags are not write-once and could, therefore, be changed or erased.
      • Password-protected firmware should require that password before changing the tag, but that's not guaranteed.
    • By allocating and tracking the identifiers yourself, there's not only the overhead of...allocating and tracking the identifiers, but also the possibility that you'll introduce duplicates if you're not careful.
    • Using asset tags for this purpose requires that all machines support setting an asset tag and properly report it to WMI.

提交回复
热议问题