在WinXP中查找哪个驱动器对应哪个USB大容量存储设备

发布于 2024-07-16 22:32:47 字数 2176 浏览 10 评论 0原文

我有多个 USB 驱动器连接到 WinXP SP3 计算机,我需要以编程方式区分它们 - 我需要找到哪个驱动器号对应于哪个设备(在本例中,一个设备 ~ 一个卷) 。 我可以使用 mountvol 获取它们的卷 ID 和驱动器号,如下所示:

C:\WINDOWS\> mountvol
\\?\Volume{bdb681b2-1ddf-11dd-bf71-806d6172696f}\
    C:\

\\?\Volume{6a8784f8-7406-11dd-a8c3-001e8c829b67}\
    A:\

此外,使用 devcon 或设备管理器,我可以看到设备 ID:

C:\WINDOWS\> devcon resources *STOR*
STORAGE\REMOVABLEMEDIA\7&190C24E5&0&RM
    Name: Generic volume
STORAGE\VOLUME\1&30A96598&0&SIGNATURED84ED84EOFFSET7E00LENGTH2543150400
    Name: Generic volume
USBSTOR\DISK&VEN_KINGSTON&PROD_DATATRAVELER2.0&REV_1.00\0803240752536&0
    Name: Kingston DataTraveler2.0 USB Device

但是,我还没有找到链接设备 ID 和卷 ID/字母的方法,就像“安全删除硬件”对话框所做的那样(因此我认为这是可能的):

通用卷 - A:
(来源:piskvor.org

如您所见,这些与我在 devcon 中看到的设备相同,并且与 mountvol 看到的卷相同; 但到目前为止我还没有找到它们之间的联系。

我发现了一些相关 问题,但这些似乎使用“无论你首先找到什么都是你的”的方法USB 设备”,这对我来说不是很有用,因为将连接多个类似的设备(同一供应商,通常是相同的产品类型)。


编辑:

@MSalters ' 答案看起来很有希望:在 XP 上,HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices 具有 REG_BINARY\DosDevices\x: (其中 >x 是 [AZ]); 注释是正确设备的 (UTF-16) 名称(例如
\DosDevices\A: = "\??\STORAGE#RemovableMedia#7&190c24e5&0&RM#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}\" ,对应于
STORAGE\REMOVABLEMEDIA\7&190C24E5&0&RM 在设备列表中看到)。

将看看这是否是要走的路。

I have several USB drives connected to a WinXP SP3 computer, and I need to tell them apart programatically - I need to find which drive letter corresponds to which device (in this case, one device ~ one volume). I can get their Volume IDs and drive letters using mountvol, looking something like this:

C:\WINDOWS\> mountvol
\\?\Volume{bdb681b2-1ddf-11dd-bf71-806d6172696f}\
    C:\

\\?\Volume{6a8784f8-7406-11dd-a8c3-001e8c829b67}\
    A:\

Also, using devcon or the Device Manager, I can see the device IDs:

C:\WINDOWS\> devcon resources *STOR*
STORAGE\REMOVABLEMEDIA\7&190C24E5&0&RM
    Name: Generic volume
STORAGE\VOLUME\1&30A96598&0&SIGNATURED84ED84EOFFSET7E00LENGTH2543150400
    Name: Generic volume
USBSTOR\DISK&VEN_KINGSTON&PROD_DATATRAVELER2.0&REV_1.00\0803240752536&0
    Name: Kingston DataTraveler2.0 USB Device

However, I haven't found a way to link the device ID and the volume ID/letter, like the "Safely remove hardware" dialog does (therefore I assume it's possible):

Generic volume - A:
(source: piskvor.org)

As you may see, these are the same devices that I see in devcon and the same volume that mountvol sees; but so far I haven't found the link between them.

I've found some related questions, but those seem to use the approach "whatever you find first is your USB device", which is not very useful in my case, since there will be several similar devices (same vendor, often same product type) connected.


Edit:

@MSalters' answer looks promising: On XP, HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices has REG_BINARY values \DosDevices\x: (where x is [A-Z]); the comment is (UTF-16) name of the correct device (e.g.
\DosDevices\A: = "\??\STORAGE#RemovableMedia#7&190c24e5&0&RM#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}\", which corresponds to
STORAGE\REMOVABLEMEDIA\7&190C24E5&0&RM seen above in the device list).

Will see if that's the way to go.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凌乱心跳 2024-07-23 22:32:48

这是一个重要的问题。 据我所知,没有官方的 API。 因此,您需要一个未记录的 API:注册表。 HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices 包含驱动器号和卷 ID 的条目。 如果您查看实际数据,您会发现它标识了驱动器。 将二进制数据视为 Unicode 字符串。 它将指向 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ENUM\。 然而,XP 和 Vista 的不同之处在于引用哪些子项以及如何引用。 (Vista 更容易,所以先尝试一下)。

It's a non-trivial question. There is no official API for it, as far as I can tell. So, you need an undocumented API: the registry. HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices contains entries for both drive letters and volume IDs. If you look at the actual data, you'll find that it identifies the drive. Look at the binary data as a Unicode string. It will point you to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ENUM\. However, XP and Vista differ in exactly what subkeys are referenced there, and how. (Vista is easier, so try that first).

邮友 2024-07-23 22:32:48

有一个官方 API 可以做到这一点。 请参阅此示例:
http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx

原理是Windows上的每个存储卷都分配有一个全局编号。 首先,您向驱动器询问其编号(通过打开“\X:”并发送 IOCTL_STORAGE_GET_DEVICE_NUMBER 请求)。 其次,您检查所有磁盘设备并询问每个磁盘设备的编号(通过不同的路径打开它,这样您就不能只是进行字符串比较)。

一旦您发现一个磁盘设备的编号与您查询驱动器的编号相同,您就知道您获胜了。

There is an official API to do this. See this sample:
http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx

The principle is that each storage volume on Windows is assigned a global number. First, you ask your drive for its number (by opening "\X:" and sending a IOCTL_STORAGE_GET_DEVICE_NUMBER request). Second, you go over all disk devices and ask each one for its number (by opening it, through a different path, so you can't just string-compare).

Once you find a disk device carrying the same number as you queried your drive, you know you have a winner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文