如何获取DevicePath的驱动器号 [英] How to get the Drive Letter for the DevicePath

查看:241
本文介绍了如何获取DevicePath的驱动器号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Win32 API。

I am using Win32 API.

真的,我不明白如何获取USB记忆棒DevicePath的驱动器号。

Really i do not understand how to get the drive letter for DevicePath of a USB stick .

您能向我解释吗

(我拥有的是SP_DEVICE_INTERFACE_DETAIL_DATA DevicePath

( what i have is SP_DEVICE_INTERFACE_DETAIL_DATA DevicePath

使用此设备路径,我会获得USB设备的VID和PID

using this Device path i get VID AND PID of the usb device

我的设备路径如下所示

\?\usb#vid_1a8d& pid_1000#358094020874450#{a5dcbf10-6530-11d2-901f-00c04fb951ed}

"\?\usb#vid_1a8d&pid_1000#358094020874450#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"

是否有任何方法可以映射驱动器字母到我的设备路径

Is there any way to to map DRIVE LETTER to my DEVICE PATH

所以请帮助我将驱动器号映射到DevicePath

so please help me to map drive letter to DevicePath )

感谢您的帮助。

推荐答案

链接我在另一个问题中提供的信息为您提供了执行此操作所需的所有信息。用半伪代码:

The link I provided in your other question gives you all the information you need to do this. In semi-pseudocode:

DiskDevice = CreateFile(DiskDevicePath);
DiskDeviceNumber = DeviceIoControl(DiskDevice, IOCTL_STORAGE_GET_DEVICE_NUMBER);
for each VolumeDevicePath in GetLogicalDriveStrings
    VolumeDevice = CreateFile(VolumeDevicePath);
    VolumeDeviceNumber = DeviceIoControl(VolumeDevice, IOCTL_STORAGE_GET_DEVICE_NUMBER);
    if(VolumeDeviceNumber == DiskDeviceNumber)
        // volume (i.e. "G:") corresponding to VolumeDevicePath resides on disk (i.e. "XYZ USB Storage Device") corresponding to DiskDevicePath

我不是100%肯定(已经有一段时间了),但是我认为磁盘设备(GUID_DEVINTERFACE_DISK)是USB设备(GUID_DEVINTERFACE_USB_DEVICE)。无论如何,我认为DiskDevicePath必须是磁盘设备(而不是USB设备)的路径。

I'm not 100% sure (it's been a while), but I think that the Disk device (GUID_DEVINTERFACE_DISK) is a child of the USB device (GUID_DEVINTERFACE_USB_DEVICE). In any event, I think DiskDevicePath needs to be the path of the Disk device (not the USB device).

这篇关于如何获取DevicePath的驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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