SetupAPI without GUID

Dear Team,

By following the below steps I can obtain the handle to the device.

  1. SetupDiGetClassDevs
  2. SetupDiEnumDeviceInterfaces
  3. SetupDiGetDeviceInterfaceDetail
  4. CreateFile

While using the above sequence I am passing the GUID of the device
which is the same value located in inf file during driver
installation.

The goal is to enumerate all the devices connected to system, obtain
its vendor id, product id, compare it with known values, and finally
open the device handle.

For this I proceeded as follows:

  1. Retrieved Device Information Set by passing DIGCF_ALLCLASSES |
    DIGCF_PRESENT flag in SetupDiGetClassDevs.

2.a. - When I try SetupDiEnumDeviceInterfaces with no guid, the result
is always ERROR_NO_MORE_ITEMS.

2.b. - On using SetupDiEnumDeviceInfo or SetupDiGetDeviceInstanceId, I
can retrieve device data and device instance id but there are no
details regarding vendor id and product id.

Kindly guide me in the correct path so that I can retrieve vendor id
and product id details of all the devices using SetupAPI.

Regards.
.

Uday Bhaskar wrote:

By following the below steps I can obtain the handle to the
device.

  1. SetupDiGetClassDevs
  2. SetupDiEnumDeviceInterfaces
  3. SetupDiGetDeviceInterfaceDetail
  4. CreateFile

While using the above sequence I am passing the GUID of the
device which is the same value located in inf file during driver
installation.

Well, that’s your first problem. Your device’s setup class GUID is a completely different concept than the device interface class GUID registered by the device driver at start time. This is probably why are you having problems.

Secondly, there’s no official way (as far as I know) to parse the USB VID and PID out of the device interface string that you’ll eventually get from SetupDiGetDeviceInterfaceDetail(). It’s in there, of course, but that’s subject to change. If you really want a foolproof way to get VID and PID, expose an IOCTL from your driver that returns this information to you.

Bhaskar wrote:

The goal is to enumerate all the devices connected to system, obtain
its vendor id, product id, compare it with known values, and finally
open the device handle.

That goal is completely hopeless. Even if you add the limitation to
“enumerate all the *USB* devices connected to system,” it’s still
hopeless. What would you DO with the device handle? If you get a
device handle to a USB mass storage device and a device handle to a USB
audio class device, they have entirely different interfaces. You can’t
just blast requests down to them.

2.b. - On using SetupDiEnumDeviceInfo or SetupDiGetDeviceInstanceId, I
can retrieve device data and device instance id but there are no
details regarding vendor id and product id.

Kindly guide me in the correct path so that I can retrieve vendor id
and product id details of all the devices using SetupAPI.

The vendor and product ID are embedded in the device instance ID.
Technically, the format is undocumented, but it is trivially easy to
reverse engineer, and the format has not changed since USB support was
first added in Windows 95 OSR2.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> The vendor and product ID are embedded in the device instance ID.

Technically, the format is undocumented

IIRC all PnP IDs formats for all popular buses are documented in MSDN.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com