user198725878
user198725878

Reputation: 6386

How to get the Drive Letter for the DevicePath

I am using Win32 API.

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

can you pls explain it to me

( what i have is SP_DEVICE_INTERFACE_DETAIL_DATA DevicePath

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

my device path looks like below

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

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

so please help me to map drive letter to DevicePath )

Thanks for any help.

Upvotes: 5

Views: 7530

Answers (2)

Luke
Luke

Reputation: 11421

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

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).

Upvotes: 7

humbagumba
humbagumba

Reputation: 2074

Take a look at this, maybe it'll help (I don't think there's an easy way to do it ...)

http://msdn.microsoft.com/en-us/library/cc542456(VS.85).aspx

Upvotes: 1

Related Questions