Windows 上的 USB 实例 ID 对于设备来说是唯一的吗? [英] is the USB Instance ID on Windows unique for a device?

查看:55
本文介绍了Windows 上的 USB 实例 ID 对于设备来说是唯一的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 系统上唯一地识别 USB 设备.由于序列号是可选的(并且在大多数设备上为空),我正在查看实例 ID.类似于USB\VID_03F0&PID_094A\6&24b73976&0&2的字段.

I'm trying to identify a USB device uniquely on a Windows system. Since serial number is optional (and empty on most devices), I'm looking at the Instance ID. The field that is like USB\VID_03F0&PID_094A\6&24b73976&0&2.

我已经知道,如果我将同一设备插入不同的端口,此 ID 会发生变化,但这对我来说没问题.问题是:如果我使用相同的设备(在我的示例中为鼠标)并将其插入,它会获得相同还是不同的实例 ID?

I already know that this ID changes if I plug the same device into different ports, but that is ok with me. The question is: If I take an identical device (mouse in my example) and plug it in, will it get the same or a different Instance ID ?

我做了一些研究,似乎没有人完全知道 VID 和 PID 背后的部分是什么.它们似乎可以识别端口和/或集线器,但如果我将不同的设备插入同一个插槽,我不仅会看到不同的 VID 和 PID,还会看到不同的垃圾.例如,这是插入同一端口的键盘:USB\VID_046D&PID_C328&MI_00\7&3f9ff46&0&0000

I've done some research and nobody seems to quite know what the parts behind VID and PID are. They do seem to identify the port and/or hub, but if I plug a different device into the same slot, I see not just different VIDs and PIDs, but also different garbage after that. For example, here's a keyboard plugged into the same port: USB\VID_046D&PID_C328&MI_00\7&3f9ff46&0&0000

Microsoft 文档和此处的相关问题均未回答此问题.

Neither the Microsoft documentation nor the related questions here answer this question.

如果我有两个相似的鼠标(或键盘,或其他),即相同的制造商和型号,如果我将它们插入相同的端口,它们会获得相同或不同的实例 ID?

If I had two similar mice (or keyboards, or whatever), i.e. same manufacturer and model, would they get the same or different Instance IDs if I plug them into the same port?

我是否有机会唯一标识特定设备(不仅仅是型号)?

Do I have any chance to uniquely identify a specific device (not just a model) ?

推荐答案

关于你的第一个问题(在标题中):

About your first question (in the title):

Windows 上的 USB 实例 ID 对于设备来说是唯一的吗?

is the USB Instance ID on Windows unique for a device?

摘自 Microsoft 设备实例 ID 页面:

设备实例 ID 是系统提供的设备标识字符串,用于唯一标识系统中的设备.

A device instance ID is a system-supplied device identification string that uniquely identifies a device in the system.

设备实例 ID 在系统重启后保持不变.

A device instance ID is persistent across system restarts.

所以,回答您的问题:

系统设备 ID 唯一标识特定 Windows 系统中的设备.

The System Device ID uniquely identifies a device in a specific Windows system.

请注意:它的任务是识别本机中的设备.从机器中取出设备后,该设备不再是这台机器的一部分.

Beware of that: its task is to identify the device in this machine. Once you remove the device from the machine, well, the device is not part of this machine anymore.

因此,现在,如果您从系统中移除设备并重新插入,您无法确定设备实例 ID 是否相同,但是:
重启系统就可以确定设备实例ID是一样的了.

So, right now, you cannot be sure that the Device Instance ID will be the same if you remove the device from the system, and plug it in again, BUT:
You can be sure that the Device Instance ID will be the same if you restart the system.

让我们继续,检查您的下一个问题.

Let's go forward, examining your next questions.

关于你的第二个问题:

如果我使用相同的设备(在我的示例中为鼠标)并将其插入,它会获得相同还是不同的实例 ID?

If I take an identical device (mouse in my example) and plug it in, will it get the same or a different Instance ID ?

让我们看看 Microsoft 设备实例 ID再次页面:

该字符串的格式由一个实例 ID 连接到一个设备 ID 组成,如下所示:

The format of this string consists of an instance ID concatenated to a device ID, as follows:

\

以下是连接到 PCI 设备的设备 ID 的实例 ID(1&08")的示例:

The following is an example of an instance ID ("1&08") concatenated to a device ID for a PCI device:

PCI\VEN_1000&DEV_0001&SUBSYS_00000000&REV_02\1&08

因此,在 USB\VID_xxx&PID_xxx\ 部分之后,您看到的是 Instance ID(名称与 System Device ID 的区别不大)

So, after the USB\VID_xxx&PID_xxx\ part, what you see is the Instance ID (little difference in the name vs System Device ID)

让我们看看 Microsoft Instance ID 页面:

实例 ID 是一个设备标识字符串,用于将设备与计算机上相同类型的其他设备区分开来.一个实例 ID 包含序列号信息,如果底层总线支持,或者某种位置信息

An instance ID is a device identification string that distinguishes a device from other devices of the same type on a computer. An instance ID contains serial number information, if supported by the underlying bus, or some kind of location information

设备的 DEVICE_CAPABILITIES 结构的 UniqueID 成员指示总线提供的实例 ID 在整个系统中是否唯一,如下所示:

The UniqueID member of the DEVICE_CAPABILITIES structure for a device indicates if a bus-supplied instance ID is unique across the system, as follows:

  • 如果 UniqueID 为 FALSE,则总线提供的设备实例 ID 仅对于该设备的总线是唯一的.即插即用 (PnP) 管理器修改总线提供的实例 ID,并将其与相应的设备 ID 组合,以创建系统中唯一的设备实例 ID.
  • 如果 UniqueID 为 TRUE,则设备实例 ID 由总线提供的设备 ID 和实例 ID 组成,用于唯一标识系统中的设备.

所以,回答您的问题:

  • 如果 UniqueIDTRUE,设备实例 ID 将是相同的,即使您将设备移动到不同的 USB 端口(我补充说:这就是当 USB 设备提供序列号时发生)
  • 如果 UniqueIDFALSE,您不能确定总线提供的实例 ID 是否相同,因此您不能确定整个设备实例 ID将是相同的.(但是,实例 ID 在系统重新启动时应该相同,因此如果您有相同的设备 1 和设备 2,并在系统重新启动期间交换它们,我假设实例 ID 将相同,因此设备实例ID 也是一样的!扩展这个,如果 device1 和 device2 是同一个设备,你可以简单地在系统重启时删除 device1 并重新插入它,并且设备实例 ID 应该是相同的!)
  • If UniqueID is TRUE, the Device Instance ID will be the same, even if you move the device to a different USB port (and I add: this is what happens when a USB Device provides a Serial Number)
  • If UniqueID is FALSE, you cannot be sure that the bus-supplied Instance ID will be the same, and so you cannot be sure that the whole Device Instance ID will be the same. (However, the Instance ID should be the same across system restarts, and so if you have device1 and device2 which are identical, and swap them during a system restart, I assume that the Instance ID will be the same, and so the Device Instance ID will be the same too! Extending this, if device1 and device2 are the same device, you could simply remove device1 and replug it during a system restart, and the Device Instance ID should be the same!)

这是因为系统设备 ID 的任务是识别系统中的设备,而不是整个世界(以及与系统分离的设备).

This is because the System Device ID's task is to identify devices in the system, not in the whole world (and so, devices detached from the system).

这也回答了您的第三个问题:

This answers your third question, too:

如果我有两个相似的鼠标(或键盘,或其他),即相同的制造商和型号,如果我将它们插入相同的端口,它们会获得相同或不同的实例 ID?

If I had two similar mice (or keyboards, or whatever), i.e. same manufacturer and model, would they get the same or different Instance IDs if I plug them into the same port?

<小时>

关于你的最后一个问题:


About your last question:

我是否有机会唯一标识特定设备(不仅仅是型号)?

Do I have any chance to uniquely identify a specific device (not just a model) ?

是的,并且(再次说到 USB)您甚至可以在全世界唯一标识特定设备,如果制造商在 USB 总线上提供序列号,AND 它保证您的序列号对于该特定(VID,PID)对是唯一的.这是一个非常严格的限制,但例如考虑一个 USB WiFi 卡(我这里有一个 Netgear):

Yes, and (speaking of USB again) you can uniquely identify a specific device even in the whole world, IF the manufacturer provides a Serial Number on the USB bus, AND it guarantees you that the Serial Number is unique for that specific (VID,PID) pair. It's a very hard constraint, but for example consider a USB WiFi card (i have a Netgear one here):

  • 它提供了 USB 序列号
  • USB 序列号正是其 MAC 地址
  • It provides the USB Serial Number
  • The USB Serial Number is exactly its MAC address

根据定义,MAC 地址是唯一的,因此您可以确保您可以唯一地标识那个设备,即使它插在不同的机器上.

Since MAC addresses are, by definition, unique, you can be sure that you can uniquely identify that device, even if it's plugged in a different machine.

但是,您无法唯一地标识所有设备或您选择的特定设备.它必须满足这些要求.

However, you cannot identify uniquely all devices, or a specific device of your choosing. It must satisfy these requirements.

我测试了前面提到的 Netgear USB WiFi 卡,它具有相同的设备实例 ID,即使插入不同的端口,甚至插入不同的机器.
我测试了一个提供 USB 序列号的通用 USB 密钥,其行为与 USB WiFi 卡相同.
在这些情况下,设备实例 ID 将类似于:

I tested the aforementioned Netgear USB WiFi card, and it has the same Device Instance ID, even when plugged in different ports, and even when plugged in different machines.
I tested a generic USB key which provides a USB Serial number, and its behavior was the same as the USB WiFi card.
In these cases, the Device Instance ID will be something like:

USB\VID_1221&PID_3234\00004700356

我测试了两个相同的通用 USB 键盘,并将它们(一次一个)插入同一个 USB 集线器端口.设备实例 ID 保持不变(此外,当我插入第二个键盘时,Windows 没有显示安装硬件"弹出窗口).设备实例 ID 为:

I tested two identical generic USB keyboards, and I plugged them (one at a time) in the same USB hub port. The Device Instance ID remained the same (and additionally, Windows didn't show the "Installing hardware" popup when I plugged in the second keyboard). The Device Instance ID was:

USB\VID_1C4F&PID_0002\7&15cdfaa&0&3

然后,我将其中一个键盘插入另一个 USB 端口,设备实例 ID 更改为:

Then, I plugged one of the keyboards on a different USB port, and the Device Instance ID changed to:

USB\VID_1C4F&PID_0002\5&2eab04ab&0&1

<小时>

更多参考

有关 USB 标识符的 Microsoft 页面

这篇关于Windows 上的 USB 实例 ID 对于设备来说是唯一的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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