如何在 Windows 10 周年更新上获取唯一的设备 ID [英] How to get unique Device IDs on Windows 10 Anniversary Update

查看:54
本文介绍了如何在 Windows 10 周年更新上获取唯一的设备 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 10 的先前版本具有 HardwareToken API (aka ASHWID) 来获取设备的唯一标识符,但它有几个缺点:

Previous iterations of Windows 10 have the HardwareToken API (aka ASHWID) to get a unique identifier for the device, but it had several drawbacks:

  • 它仅在桌面和移动平台上可用,这需要您将扩展 SDK 添加到您的项目中(并且在 HoloLens 或其他平台上不可用)
  • 在 PC 上,该值可能会随着硬件的变化而漂移"(即使只是将笔记本电脑插入扩展坞也会更改 ID),因此您需要 复杂的后端逻辑来关联设备 ID
  • 该值特定于单个应用,不能由同一发布者跨应用共享

周年更新中是否有一种新方法可以获取在所有 Windows 10 平台上一致的更有用/更稳定的 ID?我想在我的应用程序中使用 ID 来关联来自同一设备的遥测数据,以用于使用指标和广告.我不会使用该值来识别用户、创建匿名帐户、加密数据或其他任何类似的事情.它只会用于遥测目的.

Is there a new way in the Anniversary Update to get a more useful / stable ID that's consistent across all Windows 10 platforms? I want to use the ID in my apps to correlate telemetry from the same device for purposes of usage metrics and advertising. I will not use the value for identifying the user, creating anonymous accounts, encrypting data, or anything else like that. It will only be used for telemetry purposes.

我想做这样的事情:

var id = Windows.Something.GetDeviceId();  // hypothetical OS function
var telemetry = MyApp.GetUsageTelemetry(); // my own function

// Use (eg) HttpClient to send both id and telemetry to my 
// cloud infrastructure for processing and correlation
SendDataToCloudForProcessing(id, telemetry)

推荐答案

2017 年 11 月 3 日更新(新的 Registry 值,如下)

Windows 10 周年更新引入了新的 SystemIdentification type 这正是你想要的.与旧的 ASHWID 相比,它有几个优点:

The Windows 10 Anniversary Update introduced the new SystemIdentification type which does exactly what you want. It has several benefits over the old ASHWID:

  • 它适用于所有 Windows 10 平台
    • 注意:ASHWID 现在也可在所有平台上使用,但仍有上面列出的其他缺点
    • 注意:这对企业场景最有用;您不太可能在没有充分理由的情况下为 Windows 应用商店批准使用此功能的应用,因为它代表了隐私问题

    API 有一个小缺点:它不适用于某些旧 PC,因为它需要 UEFI 或 TPM.过去 5 年以上制造的大多数 PC 都应具有此硬件,并且所有其他非 PC 设备(电话、Xbox、HoloLens 等)都具有正确的硬件.如果您发现 PC 没有硬件,则需要回退到 ASHWID 或其他一些机制.

    There is one minor drawback to the API: it won't work on some old PCs, since it requires either UEFI or a TPM. Most PCs built in the last 5+ years should have this hardware, and all other non-PC devices (phone, Xbox, HoloLens, etc.) have the correct hardware. If you find a PC that doesn't have the hardware, you will need to fall back to the ASHWID or some other mechanism.

    从 Windows Fall Creator's Update(又名 1709 或 RS3 或通用 API 合同 5)开始,有 一个新的Registry标识源,它提供了一个相对稳定的ID,以防用户没有合适的硬件.如果用户重新安装操作系统(不是升级,而是新安装)或用户更改注册表,但其他方面与 Uefi 或 <代码>Tmp.

    Starting with the Windows Fall Creator's Update (aka 1709 or RS3 or Universal API Contract 5) there is a new Registry identification source which provides a relatively stable ID in case the user doesn't have appropriate hardware. It will change if the user does a fresh re-install of the OS (not an upgrade, but a new install) or if the user changes the registry, but otherwise has the same benefits as Uefi or Tmp.

    使用 API 很简单;无需在后端进行复杂的解析或考虑漂移:

    Using the API is simple; there is no need for complex parsing or accounting for drift on the back-end:

    using Windows.System.Profile;
    
    IBuffer GetSystemId()
    {
      // This sample gets the publisher ID which is the same for all apps
      // by this publisher on this device.
      // Use GetSystemIdForUser if you have the userSystemId capability
      // and need the same ID across all apps for this user (not 
      // really applicable for apps in the Windows Store)
      var systemId = SystemIdentification.GetSystemIdForPublisher();
    
      // Make sure this device can generate the IDs
      if (systemId.Source != SystemIdentificationSource.None)
      {
        // The Id property has a buffer with the unique ID
        return systemId.Id;
      }
    
      // This is a very old PC without the correct hardware. Use 
      // another mechanism to generate an ID (or perhaps just give 
      // up due to the small number of people that won't have the ID; 
      // depends on your business needs).
      return GetIdFromAshwidOrSomethingElse();
    }
    

    如问题中所述,此 ID 应仅用于后端服务中的关联目的(例如,用于遥测、广告、使用指标等).它绝不应该用于创建匿名用户帐户、识别或跟踪用户、加密用户数据等.这是因为不同的用户可以共享同一设备,或者同一用户可以在不同的设备上漫游,所以ID 不会与用户或其数据进行 1:1 映射.

    As noted in the question, this ID should only be used for purposes of correlation in a back-end service (eg, for telemetry, advertising, usage metrics, etc.). It should never be used to create anonymous user accounts, to identify or track users, to encrypt user data, etc. This is because different users can share the same device, or the same user can roam across different devices, so the ID doesn't map 1:1 with a user or their data.

    此 API 在通用 API 合同 v3 中可用,并且可以在 Windows 通用 SDK 版本 10.0.14393.0 中找到(请记住,如果您正在开发多版本应用程序并希望点亮此 API 的使用,您应该进行运行时版本检查;而应该只查询操作系统以查看 API 是否可用).

    This API is available in the Universal API Contract v3, and can be found in the Windows Universal SDK version 10.0.14393.0 (remember that if you're doing multi-version apps and want to light-up usage of this API, you should not do runtime version check; instead you should just query the OS to see if the API is available).

    这篇关于如何在 Windows 10 周年更新上获取唯一的设备 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆