From: David on
Hello
I have to find all USB flash disks on machine and read corresponding device
properties. I use SetupDiEnumDeviceInfo to find all devices on machine and
call SetupDiGetDeviceRegistryProperty with different Property param to obtain
device information. For instance, for USB flash disk I get this :

PDRP_LOCATION_INFORMATION = USB 2.0(FS) FLASH DISK
SPDRP_CLASSGUID = {36FC9E60-C465-11CF-8056-444553540000}
SPDRP_DEVICEDESC = USB Mass Storage Device
SPDRP_LOCATION_INFORMATION = USB 2.0(FS) FLASH DISK
SPDRP_MFG = Compatible USB storage device
SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = \Device\USBPDO-2
SPDRP_COMPATIBLEIDS = USB\Class_08&SubClass_05&Prot_50
SPDRP_HARDWAREID = USB\Vid_10d6&Pid_1100&Rev_0100

However I don’t see the logical driver letter here. On another hand, I can
enumerate all disks on machine (A, B, C, etc) and using DeviceIoControl
IOCTL_STORAGE_QUERY_PROPERTY can find that particuar disk drive is of type
USB Flash Disk, but again I must find match between Logical disk and device
properties.
This should be easy but I cannot find how to do this.
Thanks in advance, David.

From: Uwe Sieber on
David wrote:
> Hello
> I have to find all USB flash disks on machine and read corresponding device
> properties. I use SetupDiEnumDeviceInfo to find all devices on machine and
> call SetupDiGetDeviceRegistryProperty with different Property param to obtain
> device information.
>
> However I don’t see the logical driver letter here. On another hand, I can
> enumerate all disks on machine (A, B, C, etc) and using DeviceIoControl
> IOCTL_STORAGE_QUERY_PROPERTY can find that particuar disk drive is of type
> USB Flash Disk, but again I must find match between Logical disk and device
> properties.

The link between DISKs and CDROMs on the one and and logical
drives on the other hand it the device number which you get
by means of DeviceIoControl and IOCTL_STORAGE_GET_DEVICE_NUMBER.
This works for handles to storage volumes opened with something
like "\\.\X:" or "\\?\Volume{GUID}" and and handles to DISKs or
CDROMs opened using their pspdidd->DevicePath you get in a
SetupDi enumeration.
You may find some useful code snippets here:
http://www.codeproject.com/useritems/RemoveDriveByLetter.asp


Greetings from Germany

Uwe