Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

enumerate usb drive letters

158 views
Skip to first unread message

Anders Lindén

unread,
Dec 15, 2003, 6:05:50 PM12/15/03
to
Hello!

I have tried a lot to enumerate usb flash memories from user
mode in Windows 2000. This really beats me.
Microsofts sample usbview gives a lot of information about
usb controllers, hub and ports, but nothing about drive
letters.
With this sample, I can enumerate root hubs and their ports.
This surely gives me information about _which_ usb devices I
have in the system.
I get GUIDS and "driver key names", but not a single drive
letter.
I have also searched the registry for something that can
reveal which drive letters that has usb flash memories.
(For instance HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices and
its binary registry keys).
I have also searched on all those driver key names, root hub
names etc.

Now I start to think that it would be some way to do this
from a kernel driver.
Of course, thats the final resort.

How would that be done then?

Thanks for your attention
Anders Lindén


Maxim S. Shatskih

unread,
Dec 15, 2003, 7:15:36 PM12/15/03
to
Open each drive letter by CreateFile, send IOCTL_STORAGE_QUERY_PROPERTY and
look at the bus type.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
ma...@storagecraft.com
http://www.storagecraft.com


"Anders Lindén" <nom...@nomail.nomail> wrote in message
news:3fde3e00$1...@puffinus.its.uu.se...

Anders Lindén

unread,
Dec 16, 2003, 11:24:53 AM12/16/03
to
I tried to use IOCT_STORAGE_QUERY_PROPERTY:

bool identifyusbunits()
{
int i;
DWORD bytesreturned;
HANDLE h;
STORAGE_PROPERTY_QUERY propq;
char buff[16];
char outputbuff[1024];
DWORD num=GetLogicalDrives();
DWORD bustype;
for (i=0; i<32; i++)
{
sprintf(buff,"\\\\.\\%c:",i+'A');
propq.PropertyId=StorageDeviceProperty;
propq.QueryType=PropertyStandardQuery;
if
((h=CreateFile(buff,0,0,NULL,OPEN_EXISTING,0,NULL))!=INVALID
_HANDLE_VALUE)
{
if
(DeviceIoControl(h,IOCTL_STORAGE_QUERY_PROPERTY,&propq,sizeo
f(propq),outputbuff,1024,& bytesreturned,NULL))
{
STORAGE_DESCRIPTOR_HEADER
*hdr=(STORAGE_DESCRIPTOR_HEADER *)outputbuff;
STORAGE_DEVICE_DESCRIPTOR
*desc=(STORAGE_DEVICE_DESCRIPTOR *)(outputbuff+sizeof
(STORAGE_DESCRIPTOR_HEADER));
printf("%s: %d\n",buff,desc->BusType);
}
CloseHandle(h);
}
}
return true;
}


I got a very strange result:

\\.\B:: 16809984
\\.\C:: 0
\\.\D:: 0
\\.\E:: 0
\\.\F:: 0
\\.\G:: 0
\\.\H:: 0
\\.\I:: 16809984
\\.\J:: 16809984
\\.\Z:: 0


I and J is the ones that has USB devices, and the number
should be 7, I suppose.
Did I do something terribly wrong in my code?


"Maxim S. Shatskih" <ma...@storagecraft.com> wrote in
message news:brliqo$u72$1...@gavrilo.mtu.ru...

Anders Lindén

unread,
Dec 16, 2003, 2:17:08 PM12/16/03
to
Ah, I found the answer myself: the structure
STORAGE_DESCRIPTOR_HEADER is not separate from
the STORAGE_DEVICE_DESCRIPTOR structure, its the beginning
of it.
Now, the results gets more nice, I must say! :)

/Anders


"Anders Lindén" <nom...@nomail.nomail> wrote in message

news:3fdf3185$1...@puffinus.its.uu.se...

0 new messages