Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Uwe Sieber <mail@xxxxxxxxxxxxx>
- Date: Wed, 15 Nov 2006 09:07:35 +0100
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@xxxxxxxxxxxxxxxxxAs 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
>>
>>
- References:
- HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Nick Rivers
- Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Uwe Sieber
- Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Nick Rivers
- Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Uwe Sieber
- Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Nick Rivers
- Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Uwe Sieber
- Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- From: Nick Rivers
- HowTo obtain the assigned drive letter(s) of a USB stick?
- Prev by Date: Re: handles of a process
- Next by Date: Re: FindWindow fails for MessageBox displayed at Winlogon
- Previous by thread: Re: HowTo obtain the assigned drive letter(s) of a USB stick?
- Next by thread: Re: WindowsStation\Desktop Problem
- Index(es):
Relevant Pages
|