Re: HowTo obtain the assigned drive letter(s) of a USB stick?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Finally you need a criterion to say "yea, that's my stick".
If it's a singe one, then it's USB serial number is the
right choice. If it's a batch of sticks of the same type,
then its vendor and product id are nice. Whatever your
needs are...

Uwe


Nick Rivers wrote:
Thanks Uwe!

I know what you mean and that works for me.
But I still don´t know how I could get a match on my
USB flash if there are some other USB Flash sticks plugged
into the computer. Then I would simply find all the drive letters of all
sticks, right?


"Uwe Sieber" <mail@xxxxxxxxxxxxx> wrote in message news:4r9699Fqb8v5U1@xxxxxxxxxxxxxxxxx
As I wrote in my first answer: Get the device numbers of all
drive letters and match them with the device numbers you
got in the DISKs and CDROMs enumerations depending on the
drive type of the drive letters.
I've shown this in my RemoveDriveByLetter project for a
single drive letter. Just do it for all letters from 'A'
to 'Z'.
If the drive is mounted to an NTFS folder only then it
becomes a bit harder under XP and much harder under W2K.


Uwe




Nick Rivers wrote:
The known criterion is some device information stuff.
I am able to detect the device with reference to the 'LocaleInformation' string
using SetupDiGetDeviceRegistryProperty. That identifies my flash device exactly.
So I´ve got the corresponding DeviceInfoSet.Will that help to get the drive letter then?

"Uwe Sieber" <mail@xxxxxxxxxxxxx <mailto:mail@xxxxxxxxxxxxx>> wrote in message news:4r0rcjFp9j3kU1@xxxxxxxxxxxxxxxxx
>
>
> What is the known criterion for being a stick 'exactly this stick'?
> Do you know its drive letter, its device name, its color?
>
>
> Nick Rivers wrote:
>> Thanks so far....
>>
>> I am able to enumerate all DISKS and CDROMs using those SetupAPI
>> functions but I do not get the connection to the assigned drive letters.
>>
>> Let´s assume a bunch of USB Sticks are connected to the computer,
>> how do I identify my own one and the drive letter of exactly this stick?
>> That´s the point where I stuck.
>>
>>
>>
>> "Uwe Sieber" <mail@xxxxxxxxxxxxx <mailto:mail@xxxxxxxxxxxxx>> wrote in message
>> news:4qundfFopl0lU1@xxxxxxxxxxxxxxxxx
>>> Nick Rivers wrote:
>>>> Windows XP and later:
>>>> I need to know howto obtain the assigned drive letter(s) of a USB stick
>>>> which contains two partitions at least, a CD-ROM partition and a
>>>> removable flash partition.
>>>>
>>>> I´ve only got the HardwareID of the USB flash controller of the stick.
>>>
>>> 'Partition' isn't the right term here. These U3 sticks present
>>> themself as two drives, one removable and one CD-ROM.
>>>
>>> Enumerate all DISKs and CDROMs by means of the Setup-API as
>>> shown in my sample:
>>> http://www.codeproject.com/useritems/RemoveDriveByLetter.asp
>>>
>>> Save all their device numbers. Then get the device numbers
>>> of all drive letters.
>>>
>>> Now you can match the device numbers of CDROMs with drives
>>> that are DRIVE_CDROM and the numbers of DISKs with drives
>>> that have a DriveType DRIVE_REMOVABLE and which are no
>>> floppy drives. So far I know no good way to determine if
>>> a drive is a floppy drives. Scan for the string "floppy"
>>> in the device path or for "\\Floppy <file://\\Floppy>" in the DOS device
>>> is all I know and I don't like that.
>>> Limit this to drives which have BusTypeUsb - see
>>> IOCTL_STORAGE_QUERY_PROPERTY.
>>>
>>> Get the parent device instance handles of all DISKs and
>>> CDROMs in question. Search for a DISK and CDROM which
>>> have the same parent device instance handle.
>>>
>>>
>>> There is a shorter way but this will not work under Vista.
>>>
>>>
>>>
>>> Greetings from Germany
>>>
>>> Uwe
>>
>>


.



Relevant Pages

  • Re: USB "WD Passport" HDD w/Warp4 FP17
    ... and the help of a friend to loan me the 10.162 USB driver pack ... LVM is pretty easy to get on with - once you get used to it - and also allows rejigging of drive letters ie changing drive letter from d: to t: if required. ... However, although J: & K: are "in the system", the other two partitions are not assigned those drive letters. ... Used to support allocating a predetermined number of drive letters for a partitioned removable media device. ...
    (comp.os.os2.setup.storage)
  • Re: USB Drive and letter assignment
    ... People will use USB Cameras and sticks so when U plug a USB device letter E will automatically be affected and current E will go mad;-) ... I found the software USBDLM that suits my need and allows enforcement of a scope of drive letters that can/can not be affected to the USB connection. ... My tool ReMount is free for everyone. ...
    (microsoft.public.windowsxp.hardware)
  • Re: HowTo obtain the assigned drive letter(s) of a USB stick?
    ... USB flash if there are some other USB Flash sticks plugged ... Then I would simply find all the drive letters of all ... >> I am able to enumerate all DISKS and CDROMs using those SetupAPI ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How do I Make Drive Letters stay put?
    ... John Gregory wrote: ... Is there a positive way force the drive letters to stay put? ... it retains information about USB ... Reboot. ...
    (microsoft.public.windowsxp.general)
  • Re: HowTo obtain the assigned drive letter(s) of a USB stick?
    ... drive letters and match them with the device numbers you ... >> I am able to enumerate all DISKS and CDROMs using those SetupAPI ... >>> have the same parent device instance handle. ...
    (microsoft.public.win32.programmer.kernel)