Windows 8 的 UDIDWindows、UDID

2023-09-06 05:46:23 作者:初遇

是否有任何唯一的设备 ID (UDID) 或任何我可以在 Windows 8 上读出的不会随着硬件更改、应用重新安装等而改变的类似 ID?

Is there any unique device ID (UDID) or any similar ID I can read out on Windows 8 that doesn't change with hardware changes, app-reinstallation etc.?

如果否 - 自己生成它的最佳方法是什么?

If No - what is the best way to generate it yourself?

推荐答案

没有.是的.

不,没有这样的 ID,因为(理论上)您可以更改任何硬件组件,因此您可能会获得完全不同的 ID(这就是为什么微软建议根据 ASHWID 计算分数的原因).

No, there is not such ID because (in theory) you can change ANY hardware component so you may get a completely different ID (that's why Microsoft suggest to calculate a score based on ASHWID).

是的,有这样的 ID(但它可能不适用于您的情况).如果您不能依赖硬件,因为添加内存、更换磁盘、添加另一个网卡(例如打开/关闭蓝牙或 wi-fi)很容易,那么您必须依赖软件"ID.

Yes, there is such ID (but it may not be applicable in your case). If you can't rely on hardware because it's easy to add memory, change disks, add another network card (for example turning on/off bluetooth or wi-fi) then you have to rely on a "software" ID.

在注册表中有一个在 Windows 安装过程中生成的唯一 ID,在您重新安装 Windows 之前它不会改变.您可以在 HKLM/Software/Microsoft/Cryptography 中找到这样的 ID,它是一个名为 MachineGuid 的字符串.

In the registry there is an unique ID generated during Windows installation and it won't change until you reinstall Windows. You can find such ID in HKLM/Software/Microsoft/Cryptography, it's a string named MachineGuid.

如果您可以确定一个您非常确定不会更改的组件(例如主板),您可以使用简单的 WMI 查询来获取其序列号,但您应该始终提供备用,因为许多 MB 返回一个假的S/N(并且虚拟机可能总是返回相同的).什么是正确的解决方案......这取决于你必须用那个 ID 做什么.识别用户?检查许可证?加密数据?其中每一个都有不同的 ID最佳实践".

If you can identify a component you're pretty sure that won't change (motherboard for example) you may use a simple WMI query to get its serial number but you should always provide a fallback because many many MBs returns a fake S/N (and virtual machines may returns always the same one). What's the proper solution...well it depends on what you have to do with that ID. Identify the user? Check for license? Encrypt data? Each of these has a different "best practice" for ID.

获取设备的唯一 ID如果您必须识别特定设备(无论用户如何),您有很多选择,我更愿意做的是仅使用稳定数据(例如来自主板和 BIOS 的 S/N)生成一个 ID.如果他/她完全更新硬件,这对您没有帮助,但它应该是稳定的足够(但你必须定义什么是足够在你的情况下).您甚至可以使用主磁盘的 S/N(对于便携式设备,它非常稳定,您甚至可以将它与其他序列号结合使用来构建您自己的 ID).您可以通过 WMI 或(如果您的目标是 WinRT)通过 ASHWID 结构的特定字节获取此信息.

Get an unique ID for the device If you have to identify a particular device (regardless to the user) you have many options, what I'd prefer to do is to generate an ID using only stable data (S/N from motherboard and BIOS, for example). This won't help you if he/she completely renew its hardware but it should be stable enough (but you have to define what is enough in your case). You may even use the S/N of the primary disk (with portable devices it's pretty stable and you may even use it in combination with other serial numbers to build your own ID). You can get this informations through WMI or (if you're targeting WinRT) through specific bytes of the ASHWID structure.

加密数据在这种情况下,您必须考虑数据何时可能不可恢复.如果通过一个小的硬件更改,您的用户将无法很好地阅读他们以前的文件,他们会不高兴.在这种情况下,我建议使用 MachineGuid,除非他们重新安装操作系统,否则他们不必担心(但帮他们一个忙,并提供一种在某处读回该 GUID 的方法).如果您确定您的目标是手机或平板电脑等便携式设备,那么磁盘序列号(或 CPU ID,如果可用,或 MB 或 BIOS)也可能是合适的(因为它们会改变的情况很少见).

Encrypt data In this case you have to think when data may be unrecoverable. If with a small hardware change your users won't be able to read their previous files well, they'll be unhappy. In this case I would suggest to use the MachineGuid, unless they reinstall the OS they wouldn't have to worry (but do them a favor and provide a way to read back that GUID somewhere). If you're sure you're targeting a portable device like a phone or a tablet then disk serial number (or CPU ID, if available, or MB or BIOS) may be appropriate too (because it's pretty uncommon they'll change).

许可我会使用许多(稳定)ID 的组合.至于设备的唯一标识符,您不能确定什么都不会改变.在过去,MAC 地址被广泛用于此,但移动设备改变了这些规则(因为很容易关闭 NIC).您仍然可以使用它们,但您必须格外小心(和代码)来管理这种情况.同样,多个 ID 的组合(仔细选择)可以帮助您在客户更改硬件/软件设置时最大程度地减少客户的工作量.在这种情况下,一个很好的折衷方案可能是操作系统序列号(而不是 MachineGuid).如果他们安装了新的操作系统,那么他们也必须更新您的许可证(但我会将它与其他东西结合使用,以确保他们不会在多台计算机或虚拟机上使用相同的操作系统副本).

Licensing I would use a combination of many (stable) IDs. As for an unique identifier for the device you can't be sure nothing will change. In the past MAC address was vastly used for this but mobile devices changed these rules (because it's easy to turn off a NIC). You can still use them but you have to put extra care (and code) to manage that situation. Again a combination of multiple IDs (chosen carefully) can help you to minimize customers effort when they change their hw/sw setup. In this case a good compromise could be the OS serial number (not the MachineGuid). If they install a new OS then they have to update your license too (but I would use it combined with something else to be sure they won't use the same OS copy on multiple computers or virtual machines).

关于虚拟机的注意事项如果您也必须以虚拟机为目标,那么事情就会变得更加复杂.理论上,用户可以使用完全相同的硬件和软件配置创建同一 VM 的多个副本.如果这是一个问题,如果你不能正确解决这个问题(例如使用网络检查)我建议你根本不支持它们(只是退出如果您检测到虚拟机).

Note about virtual machines If you have to target VMs too then things become more complicated. In theory an user can create multiple copies of the same VM with exactly the same hardare and software configuration. If this is an issue and if you can't address this properly (for example using a network check) I would suggest you don't support them at all (just quit if you detect a VM).