Getting the drive letter from a USB insert notification

T

Terry

I've been having a heck of a time figuring out how to do this - maybe
someone can help? My goal is to figure out which drive letter is assigned
to a mass storage device when it is connected.

I've been playing with the usblib driver and I can see the vendor and
product ID of the device being connected, which is helpful, but I don't see
any way of correlating that with the drive letter that it was assigned by
the OS. I'm beginning to think I'm approaching this from the wrong end - it
seems the device manager in Windows has some knowledge of the hardware
connected to a USB bus, but can't seem to find the right group of API calls.

Any help would be appreciated.

Thanks,
Terry
 
M

mikeyhsd

normally it would be the next avalable letter in line.
check with Explorer should list it and have a letter assigned.



(e-mail address removed)



I've been having a heck of a time figuring out how to do this - maybe
someone can help? My goal is to figure out which drive letter is assigned
to a mass storage device when it is connected.

I've been playing with the usblib driver and I can see the vendor and
product ID of the device being connected, which is helpful, but I don't see
any way of correlating that with the drive letter that it was assigned by
the OS. I'm beginning to think I'm approaching this from the wrong end - it
seems the device manager in Windows has some knowledge of the hardware
connected to a USB bus, but can't seem to find the right group of API calls.

Any help would be appreciated.

Thanks,
Terry
 
O

Olaf Doschke

Hi Terry,

windows messages can be a solution.

You get the WM_DEVICECHANGE
message, if a device was added or removed

And a WM_USER_SHNOTIFY
message can then tell you, what drive letter
you got

You get these parameters with the
window event: hWnd, Msg, wParam, lParam
All integers.

lparam will be SHCNE_DRIVEADD
if you get Msg=WM_USER_SHNOTIFY
and the drive was added.

wParam will then be the pointer to a dword
containing a handle for SHGetPathFromIDList.

If you are not familiar with windows messaging,
you may also use WMI to monitor device changes.

Bye, Olaf.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top