From: Uwe Sieber on 11 May 2007 03:10
> On May 11, 12:27 am, Uwe Sieber <m...(a)uwe-sieber.de> wrote:
>> galapogos wrote:
>>> On May 10, 6:27 pm, Uwe Sieber <m...(a)uwe-sieber.de> wrote:
>>>> galapogos wrote:
>>>>> I'm wondering how I can scan the system for USB devices and read off
>>>>> the USB descriptors such as VID/PID/serial number in C? I have an
>>>>> external USB HDD that I wish to access, and I'm currently able to do
>>>>> so with DeviceIoControl by addressing it as PhysicalDriveX, which will
>>>>> return me information about the device, except it only does it for the
>>>>> attached fixed disk, rather than the USB device.
>>>> Use an SetupDi enumeration for DISKs, you find your drive by
>>>> its DeviceNumber. The USB device is the disk's parent device.
>>>> I've shown this in a sample:http://www.codeproject.com/system/RemoveDriveByLetter.asp
>>>> In the demo project there are some comment lines about
>>>> the USB serial.
>>>> Greetings from Germany
>>> Hi Uwe,
>>> Thanks for the link. I'll try it out tomorrow, but I've taken a brief
>>> look at it. It seems to support volumes and disks. For my application,
>>> the drive will be a fixed disk in a USB enclosure, and it will be
>>> uninitialized/unpartitioned/unformatted. I'm accessing it RAW using
>>> ReadFile() and WriteFile(), so it will be accessed with "\\.
>>> \PhysicalDriveX" rather than "\\.\X:". Will that change anything? Or
>>> will it only eliminate the volume level(child of the disk)?
>> This saves the step to determine the device number
>> of the storage volume. Obviously you know the device
>> number, it's the X in "\\.\PhysicalDriveX".
>> On fixed disks the volume is not the child device of
>> the disk.
> Hi again,
> OK so I fixed the compile error and after a bit of coding, I'm able to
> get the information of the USB bridge(parent of the disk) with a
> CM_Get_Device_ID() call, and this includes the USB VID, PID and SN,
> exactly what I need. It however stores them as a string in the format
> "USB\VID_XXXX&PID_YYYY\ZZZZ", where XXXX is the VID, YYYY is the PID
> and ZZZZ is the SN. Is there any function I can call to extract the 3
> fields into separate buffers, or must I write the function myself?
You must write it yourself.
From: egray1 on 15 May 2007 18:14
Take a look at the following article... it's in VB.Net (but the
concepts are the same). There is also a C# demonstration source code
project that is version of the USBView application.