Getting list of devices a driver owns

Ok, I see that WdfVerifier.exe can show me a list of drivers, and what Plug and Play devices that driver owns. I need to do something very similar. Is there an API that will let me extract this information from the system? I can already use the Setup API to make sure the driver I’m interested in is actually there, would the Setup API docs be a good place to start?

Links, etc. very welcomed!

…ed…

Have to love answering my own question, but I’m not sure if this is the canonical way or not!

There’s an entry for the driver in the CurrentControlSet section of the registry that contains the info I need in “Enum”. I would assume I could open the registry key and suck this information out for my own nefarious purposes - is this the Right Thing™?

…ed…

Probably not.

What do you need specifically? What information per driver? Just one or
all drivers?

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@woolyloach.com
Sent: Monday, October 11, 2010 5:10 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Getting list of devices a driver owns

Have to love answering my own question, but I’m not sure if this is the
canonical way or not!

There’s an entry for the driver in the CurrentControlSet section of the
registry that contains the info I need in “Enum”. I would assume I could
open the registry key and suck this information out for my own nefarious
purposes - is this the Right Thing™?

…ed…


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@woolyloach.com wrote:

Have to love answering my own question, but I’m not sure if this is the canonical way or not!

There’s an entry for the driver in the CurrentControlSet section of the registry that contains the info I need in “Enum”. I would assume I could open the registry key and suck this information out for my own nefarious purposes - is this the Right Thing™?

No. That contains information about every PnP device your computer has
ever seen, whether it is currently present or not. It does not deal
with legacy devices at all.

It depends on exactly what you want, but you should look at the
EnumDeviceDrivers API.


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

I need the strings that contain the Vendor ID/device/etc. that is of the form:

PCI\VEN_8086&DEV_3B56&SUBSYS_040A1028&REV_05\3&11583659&0&D8

…so that I can use that information to unload a previously loaded driver with DEVCON and create a custom INF that allows my driver to take ownership of the device in Windows PE. I’ve been hand-hacking an INF to make this happen but it needs to be generated programatically by our test app.

The driver is, in specific, hdaudbus.sys.

I suspect I could get away with this in WinPE as registry changes don’t make it across reboots, IIRC, and I can (safely?) assume I can take advantage of that lack of persistence.

Look at the list of imports that wdfverifier has, that should lead you down the proper path. Also, IIRC devcon has some ability to enumerate devices based on driver

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@woolyloach.com
Sent: Monday, October 11, 2010 1:49 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Getting list of devices a driver owns

Ok, I see that WdfVerifier.exe can show me a list of drivers, and what Plug and Play devices that driver owns. I need to do something very similar. Is there an API that will let me extract this information from the system? I can already use the Setup API to make sure the driver I’m interested in is actually there, would the Setup API docs be a good place to start?

Links, etc. very welcomed!

…ed…


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Well, since I wrote all of the WdfVerifier tool, how about I just tell you how I did it?

I used SetupDiGetClassDevs to get all the devices in any hardware profile whether present or not (because that is what I wanted but it probably isn’t what you want). I used SetupDiEnumDeviceInfo to go through the list one device at a time. For each device I used SetupDiGetDeviceRegistryProperty to see if a particular driver was Service, an Upper Filter, or a Lower Filter (SPDRP_SERVICE, SPDRP_UPPERFILTERS, SPDRP_LOWERFILTERS). How I got a list of all the drivers I was interested in- that was complicated, and you don’t need to know that to solve your problem.

That’s it- about as direct a way to do it as I can think of. As noted in tooltips and documentation, this won’t catch drivers used as class filters- I know how to do that, but I had limited time, and it was extremely unlikely this was needed. It does pick up the devnodes created for legacy services (created when you “install” using Win32 CreateService), which would include file system filters, IIRC- not that I actually wanted to catch them, as at the time, I did not expect anybody to use KMDF to write one. But keeping them out would also have been extra work, and time was limited. I tried to write only what I needed.

But you probably don’t want to do it that way- you can probably limit the size of the tree you’re searching by setup class, for instance, and you also probably only want devices present in the current hardware profile.

-----Original Message-----
To: Windows System Software Devs Interest List
Subject: [ntdev] Getting list of devices a driver owns

Ok, I see that WdfVerifier.exe can show me a list of drivers, and what Plug and Play devices that driver owns. I need to do something very similar. Is there an API that will let me extract this information from the system? I can already use the Setup API to make sure the driver I’m interested in is actually there, would the Setup API docs be a good place to start?

Links, etc. very welcomed!

…ed…

And before someone points this out- yes, I used SetupDiGetDeviceInstanceId to get that information, which is what I actually display.

Since you want hardware ID and not instance ID, you can use the SetupDiGetDeviceRegistryProperty API with SPDRP_HARDWAREID.

-----Original Message-----
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Getting list of devices a driver owns

Well, since I wrote all of the WdfVerifier tool, how about I just tell you how I did it?

I used SetupDiGetClassDevs to get all the devices in any hardware profile whether present or not (because that is what I wanted but it probably isn’t what you want). I used SetupDiEnumDeviceInfo to go through the list one device at a time. For each device I used SetupDiGetDeviceRegistryProperty to see if a particular driver was Service, an Upper Filter, or a Lower Filter (SPDRP_SERVICE, SPDRP_UPPERFILTERS, SPDRP_LOWERFILTERS). How I got a list of all the drivers I was interested in- that was complicated, and you don’t need to know that to solve your problem.

That’s it- about as direct a way to do it as I can think of. As noted in tooltips and documentation, this won’t catch drivers used as class filters- I know how to do that, but I had limited time, and it was extremely unlikely this was needed. It does pick up the devnodes created for legacy services (created when you “install” using Win32 CreateService), which would include file system filters, IIRC- not that I actually wanted to catch them, as at the time, I did not expect anybody to use KMDF to write one. But keeping them out would also have been extra work, and time was limited. I tried to write only what I needed.

But you probably don’t want to do it that way- you can probably limit the size of the tree you’re searching by setup class, for instance, and you also probably only want devices present in the current hardware profile.

-----Original Message-----
To: Windows System Software Devs Interest List
Subject: [ntdev] Getting list of devices a driver owns

Ok, I see that WdfVerifier.exe can show me a list of drivers, and what Plug and Play devices that driver owns. I need to do something very similar. Is there an API that will let me extract this information from the system? I can already use the Setup API to make sure the driver I’m interested in is actually there, would the Setup API docs be a good place to start?

Links, etc. very welcomed!

…ed…

You can write a simple WDTF script to do this. WDTF is shipped with WDK.
http://msdn.microsoft.com/en-us/library/ff539547(v=VS.85).aspx

First, install WDTF on the client machine. Then use EnumDevices.wsf script under WDTF sample scripts as a sample to create your own script:

var Devices = WDTF.DeviceDepot.Query(“Service= AND IsPhantom=‘False’”);
for (var idx in Devices)
{
WScript.Echo(Device.GetValue(“HardwareID”);
}

@Bob - you rock! That’s exactly what I needed to know!

BTW, WdfVerifier is a very useful tool - saved me a lot of lost hair in the past 2 weeks.

@whql - I wish I could use scripting, but this is a system booted off a WinPE stick without scripting enabled, used on the factory floor - I have no control over the environment. It’d be nice…

…ed…