Uwe
Thu Jun 07 02:13:41 CDT 2007
All this can be done thru documented API calls, there
is absolutely no reason to play with the registry.
Uwe
m4rk.gm4il@gmail.com wrote:
> Hi,
>
> Try this - the easiest way, It worked for me, I dont know if it will work
> for you.
> I also need other's help on this because i dont have all kinds of USB flash
> storage device to test my service application. If it does work not for you,
> pls send me an email coz we are on similar situation.
>
> 1> monitor for registry changes under the registry key:
>
> HKLM\SYSTEM\CurrentControlSet\Enum\USBSTOR
>
> 2> Once a USB device is inserted onto the USB port, changes
> on the registry will be notified thru RegNotifyChangeKeyValue() API
> or ur service app will have DBT_DEVICEARRIVAL notification.
>
> 3> As soon as there were changes, your application should enumerate the
> specified registry subkey and then check for the existence of "Control"
> subkeyname.
>
> 4> The "Control" subkey, will have a "DeviceReference" valuename under it
> with a DWORD value data that refers to that device. - what's the use of that
> value data ? i really dont know.
>
> 5> Get the PARENT Subkey of this branch because it holds the
> "ParentIdPrefix" valuename which has a REG_SZ type of value data.
>
> 6> We can use this "ParentIdPrefix" in determining the assigned drive of that
> newly inserted USB device. We will then scan the value data under the
> registry tree:
>
> HKLM\System\MountedDevices
>
> 7> We will only search under those Value name starting with
> \DosDevices\<drive letter>. Since this is a binary value, we will
> get all of its string equivalent then we will search among those
> string equivalent where we can find the valuedata of "ParentIdPrefix" which
> refers to the inserted USB drive. The valuename which holds this value data
> represent the Drive letter assigned to the USB drive. Remove the
> "\DosDevices\" string
> to produce the drive letter assignment.
>
> 8> Once you get the drive letter assignment, we can also get the
> disk geometry: ( Disk size, tracks per cylinder, sectors per track, etc. )
> of the USB device. - i tried this only on limited device samples.
>
> 9> As soon as the USB device is removed from the USB port, the
> "DeviceReference" value is removed from that Registry tree.
>
> 10> The advantages of this technique is that you can enumerate the USB
> device even if the flash drive is already inserted even before your service
> application has started. - a little tweak will do it.
>
> 11> In Windows 2000, you can get the following important
> information in the registry:
>
> 1> USB Friendly Name - the recognizable name for the USB.
> 2> Class GUID - The GUID for removable media
> 3> Device Description - the description for the USB, if this is a flash
> drive then the description is "Disk Drive".
> 4> Driver - The generic driver used for this USB.
> 5> Manufacturer - this does not give accurate information - it usually gives
> "(Standard disk drive)" value and not the actual manufacturer of the USB.
> 6> USB drive - drive letter assignment for this device.
>
> 12> if your devt platform is XP or higher, you can also get the serial number.
>
> 13> check this site:
>
>
http://www.osronline.com/lists_archive/ntdev/thread11983.html
>
>
>
> "Ilia Golubev" wrote:
>
>> Hi,
>>
>> I'm writing NT Service that listens device notifications. I am
>> subscribing on DEV_BROADCAST_DEVICEINTERFACE notifications. After USB
>> (flash drive or HDD) is connected, I get DBT_DEVICEARRIVAL notification.
>> The notification contains the string \\?\Description{GUID}. I find the
>> same string in the registry HKLM\CONFIG\...\DeviceClasses\... But I
>> cannot know how to get its drive letter?
>>
>> Any help would be appreciated.
>>
>> Ilia
>>