How do you programmatically force setupdi to load a particular driver

I have a problem I hope someone out there more acquainted with programmatic installation of drivers can help me with. I need to programmatically update a windows 7 driver and force it to load a different driver than is already loaded. Both of these drivers are signed, the only difference is that the installed driver is a better match for the device than the older driver.

Can someone who has done this tell me what needs to be done? I have tried a bunch of different methods but I can’t make it work. I know there must be a way since it can be done via the update driver dialog…

Thanks

Mark Cariddi
OSR Open Systems Resources, inc

Mark,

What is the class of the driver package?

DIFx supports a ‘force’ function which (purportedly) will select the driver
regardless of rank.

You mention a few schemes as having been tried. Do any of those attempts
involve calling SetupDI functions to explicitly select the driver package
you want to install? If so, how did that fail?

Cheers,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Thursday, October 14, 2010 2:00 PM
To: Windows System Software Devs Interest List
Cc: Mark Cariddi
Subject: [ntdev] How do you programmatically force setupdi to load a
particular driver

I have a problem I hope someone out there more acquainted with programmatic
installation of drivers can help me with. I need to programmatically
update a windows 7 driver and force it to load a different driver than is
already loaded. Both of these drivers are signed, the only difference is
that the installed driver is a better match for the device than the older
driver.

Can someone who has done this tell me what needs to be done? I have tried
a bunch of different methods but I can’t make it work. I know there must
be a way since it can be done via the update driver dialog…

Thanks

Mark Cariddi
OSR Open Systems Resources, inc


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

The class of the driver package is 1394. I want to switch between the win7 1394 bus driver and the legacy bus driver.

I have never looked at the Difx apis, so I guess I have some research to do. As for the setupdI functions I have only ever done the most basic stuff with it. I don’t see a way to tell it the exit driver I want it to load. When I pass in the hardware id it always uses the same driver. I need some way to tell it the exact entry in the manufacturer section that I want it to load…

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Thursday, October 14, 2010 2:33 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

Mark,

What is the class of the driver package?

DIFx supports a ‘force’ function which (purportedly) will select the driver regardless of rank.

You mention a few schemes as having been tried. Do any of those attempts
involve calling SetupDI functions to explicitly select the driver package you want to install? If so, how did that fail?

Cheers,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Thursday, October 14, 2010 2:00 PM
To: Windows System Software Devs Interest List
Cc: Mark Cariddi
Subject: [ntdev] How do you programmatically force setupdi to load a particular driver

I have a problem I hope someone out there more acquainted with programmatic
installation of drivers can help me with. I need to programmatically
update a windows 7 driver and force it to load a different driver than is
already loaded. Both of these drivers are signed, the only difference is
that the installed driver is a better match for the device than the older driver.

Can someone who has done this tell me what needs to be done? I have tried
a bunch of different methods but I can’t make it work. I know there must
be a way since it can be done via the update driver dialog…

Thanks

Mark Cariddi
OSR Open Systems Resources, inc


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


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, I tried the DriverPackageInstallFunction and as with the setupDi calls
I tried, it is not installing the legacy bus driver, it is sticking with the
originally loaded driver…

Any other suggestions?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Thursday, October 14, 2010 2:53 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

The class of the driver package is 1394. I want to switch between the
win7 1394 bus driver and the legacy bus driver.

I have never looked at the Difx apis, so I guess I have some research to do.
As for the setupdI functions I have only ever done the most basic stuff with
it. I don’t see a way to tell it the exit driver I want it to load.
When I pass in the hardware id it always uses the same driver. I need
some way to tell it the exact entry in the manufacturer section that I want
it to load…

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Thursday, October 14, 2010 2:33 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

Mark,

What is the class of the driver package?

DIFx supports a ‘force’ function which (purportedly) will select the driver
regardless of rank.

You mention a few schemes as having been tried. Do any of those attempts
involve calling SetupDI functions to explicitly select the driver package
you want to install? If so, how did that fail?

Cheers,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Thursday, October 14, 2010 2:00 PM
To: Windows System Software Devs Interest List
Cc: Mark Cariddi
Subject: [ntdev] How do you programmatically force setupdi to load a
particular driver

I have a problem I hope someone out there more acquainted with programmatic
installation of drivers can help me with. I need to programmatically
update a windows 7 driver and force it to load a different driver than is
already loaded. Both of these drivers are signed, the only difference is
that the installed driver is a better match for the device than the older
driver.

Can someone who has done this tell me what needs to be done? I have tried
a bunch of different methods but I can’t make it work. I know there must
be a way since it can be done via the update driver dialog…

Thanks

Mark Cariddi
OSR Open Systems Resources, inc


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


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


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

I didn’t answer earlier because I can’t say I’ve specifically done it, and that was a condition of the original request.

But since nobody has mentioned it:

If the legacy driver is in a different INF, UpdateDriverForPlugAndPlayDevice http://msdn.microsoft.com/en-us/library/ff553534(v=VS.85).aspx

with INSTALLFLAG_FORCE seems like it should do what you’re asking.

This should be what devcon update uses, unless my memory has failed again.

HI, Thanks I tried that also. It also keeps the original driver and won’t let me load the legacy driver over it…

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Thursday, October 14, 2010 3:32 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

I didn’t answer earlier because I can’t say I’ve specifically done it, and that was a condition of the original request.

But since nobody has mentioned it:

If the legacy driver is in a different INF, UpdateDriverForPlugAndPlayDevice http://msdn.microsoft.com/en-us/library/ff553534(v=VS.85).aspx

with INSTALLFLAG_FORCE seems like it should do what you’re asking.

This should be what devcon update uses, unless my memory has failed again.


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

On Fri, Oct 15, 2010 at 7:00 AM, Mark Cariddi wrote:
> I have a problem I hope someone out there more acquainted with programmatic installation of drivers can help me with. ? ?I need to programmatically update a windows 7 driver and force it to load a different driver than is already loaded. ? ?Both of these drivers are signed, the only difference is that the installed driver is a better match for the device than the older driver.
>
> Can someone who has done this tell me what needs to be done? ? ?I have tried a bunch of different methods but I can’t make it work. ? I know there must be a way since it can be done via the update driver dialog…
>

The easiest way is dpinst.exe with the forceIfDriverIsNotBetter flag,
there is also a quietInstall flag to suppress UI
(http://msdn.microsoft.com/en-us/library/ff544775(VS.85).aspx).
You can use the process return code to determine installation success
or failure and whether a reboot is required etc
(http://msdn.microsoft.com/en-us/library/ff544790(VS.85).aspx).

If nothing else it is a quick way to tell if the DIFx library has the
functions you need.

Thanks, but DpInst has the same issues every other API I have found has, which is that it won’t let me tell it exactly which model of a device I want loaded. For example, I want hardware ID PCI\CC_0C0010 to load (legacy bus driver), unfortunately the device that is currently loaded PCI\VEN_104C&CC_0C0010 is already loaded (win7 bus driver) so since PCI\CC_0C0010 is a compatible ID it won’t load the legacy bus driver. I need some way to explicitly tell an API that I want DRIVER X. I have not found that… But Device Manager Update can do it…

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Daniel Newton
Sent: Thursday, October 14, 2010 5:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How do you programmatically force setupdi to load a particular driver

On Fri, Oct 15, 2010 at 7:00 AM, Mark Cariddi wrote:
> I have a problem I hope someone out there more acquainted with programmatic installation of drivers can help me with. ? ?I need to programmatically update a windows 7 driver and force it to load a different driver than is already loaded. ? ?Both of these drivers are signed, the only difference is that the installed driver is a better match for the device than the older driver.
>
> Can someone who has done this tell me what needs to be done? ? ?I have tried a bunch of different methods but I can’t make it work. ? I know there must be a way since it can be done via the update driver dialog…
>

The easiest way is dpinst.exe with the forceIfDriverIsNotBetter flag, there is also a quietInstall flag to suppress UI (http://msdn.microsoft.com/en-us/library/ff544775(VS.85).aspx).
You can use the process return code to determine installation success or failure and whether a reboot is required etc (http://msdn.microsoft.com/en-us/library/ff544790(VS.85).aspx).

If nothing else it is a quick way to tell if the DIFx library has the functions you need.


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

I cannot find a full-up code sample to share at the moment but I believe it
all hinges around building a DeviceInfoSet which contains your device,
adding the driver you want, and then calling SetupDiSetSelectedDriver().
At that point, it is a call to SetupDiCallClassInstaller(DIF_INSTALLDEVICE,
…) or some such.

I will root around for working code. It must be under a rock here
somewhere…

Good Luck,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Thursday, October 14, 2010 5:29 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

Thanks, but DpInst has the same issues every other API I have found has,
which is that it won’t let me tell it exactly which model of a device I want
loaded. For example, I want hardware ID PCI\CC_0C0010 to load (legacy
bus driver), unfortunately the device that is currently loaded
PCI\VEN_104C&CC_0C0010 is already loaded (win7 bus driver) so since
PCI\CC_0C0010 is a compatible ID it won’t load the legacy bus driver. I
need some way to explicitly tell an API that I want DRIVER X. I have not
found that… But Device Manager Update can do it…

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Daniel Newton
Sent: Thursday, October 14, 2010 5:06 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How do you programmatically force setupdi to load a
particular driver

On Fri, Oct 15, 2010 at 7:00 AM, Mark Cariddi wrote:
> I have a problem I hope someone out there more acquainted with
programmatic installation of drivers can help me with. ? ?I need to
programmatically update a windows 7 driver and force it to load a different
driver than is already loaded. ? ?Both of these drivers are signed, the only
difference is that the installed driver is a better match for the device
than the older driver.
>
> Can someone who has done this tell me what needs to be done? ? ?I have
tried a bunch of different methods but I can’t make it work. ? I know there
must be a way since it can be done via the update driver dialog…
>

The easiest way is dpinst.exe with the forceIfDriverIsNotBetter flag, there
is also a quietInstall flag to suppress UI
(http://msdn.microsoft.com/en-us/library/ff544775(VS.85).aspx).
You can use the process return code to determine installation success or
failure and whether a reboot is required etc
(http://msdn.microsoft.com/en-us/library/ff544790(VS.85).aspx).

If nothing else it is a quick way to tell if the DIFx library has the
functions you need.


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


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

With some hesitancy as this may not be helpful, and it probably sounds terribly un-Microsoft:

I’m facing this same basic problem, and this is a basic sketch of how I intend to approach it, based upon previous work I’ve done of this sort. But not having completed this task, I can’t tell you what rough edges remain in this sketch (this assumes the INF with your legacy driver is already known to the system):

Get one or more SP_DEVINFO_DATA’s for the specific device(s) to update this way [I thought I’d leave the details of how out for now, a lot of people know them], then for each one:

SetupDiBuildDriverIntoList- get a list of all the compatible drivers
SetupDiEnumDriverInfo- go through that list until I find the driver I want to force, then:
SetupDiSetSelectedDriver- to force that to be the driver selected for that device, then:
setup some appropriate class installer parameters so I can use
SetupDiCallClassInstaller DIF_INSTALLDEVICE- to do the rest of the installation work.

Like I said, a sketch- I’ll add that where I usually go wrong when first working through these is knowing when to call the class installer and when to bypass it and go directly to the API. I don’t find it always intuitive whom does what to whom [and the installer is a black box, after all], although it usually doesn’t take too long to sort out once things are rolling and going every which way.

Thanks I’ll see where this leads me and get back to you all.

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Thursday, October 14, 2010 6:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

With some hesitancy as this may not be helpful, and it probably sounds terribly un-Microsoft:

I’m facing this same basic problem, and this is a basic sketch of how I intend to approach it, based upon previous work I’ve done of this sort. But not having completed this task, I can’t tell you what rough edges remain in this sketch (this assumes the INF with your legacy driver is already known to the system):

Get one or more SP_DEVINFO_DATA’s for the specific device(s) to update this way [I thought I’d leave the details of how out for now, a lot of people know them], then for each one:

SetupDiBuildDriverIntoList- get a list of all the compatible drivers
SetupDiEnumDriverInfo- go through that list until I find the driver I want to force, then:
SetupDiSetSelectedDriver- to force that to be the driver selected for that device, then:
setup some appropriate class installer parameters so I can use SetupDiCallClassInstaller DIF_INSTALLDEVICE- to do the rest of the installation work.

Like I said, a sketch- I’ll add that where I usually go wrong when first working through these is knowing when to call the class installer and when to bypass it and go directly to the API. I don’t find it always intuitive whom does what to whom [and the installer is a black box, after all], although it usually doesn’t take too long to sort out once things are rolling and going every which way.


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

On Fri, Oct 15, 2010 at 2:00 AM, Mark Cariddi wrote:
> ?Both of these drivers are signed, the only difference is that the
> installed driver is a better match for the device than the older driver.
>
> Can someone who has done this tell me what needs to be done?

Maybe libwdi can help. We use it for WinUSB and libusb-win32
driver installation (to replace existing drivers) but it is not
limited to WinUSB or libusb-win32. It might work
for you as well.

http://www.libusb.org/wiki/libwdi
It is LGPL, so you should be able to use it with your own
application without releasing your own source code.


Xiaofan

Hi Bob, I have a question. I did do the steps you have listed here, but I must be missing something. When I did the setupdiBuildDriverInfoList and then call setupdiEnumDriverInfo, I only get the driver that is loaded, I don’t get the drivers that are listed in the INF file also. Am I missing something here?

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Thursday, October 14, 2010 6:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

With some hesitancy as this may not be helpful, and it probably sounds terribly un-Microsoft:

I’m facing this same basic problem, and this is a basic sketch of how I intend to approach it, based upon previous work I’ve done of this sort. But not having completed this task, I can’t tell you what rough edges remain in this sketch (this assumes the INF with your legacy driver is already known to the system):

Get one or more SP_DEVINFO_DATA’s for the specific device(s) to update this way [I thought I’d leave the details of how out for now, a lot of people know them], then for each one:

SetupDiBuildDriverIntoList- get a list of all the compatible drivers
SetupDiEnumDriverInfo- go through that list until I find the driver I want to force, then:
SetupDiSetSelectedDriver- to force that to be the driver selected for that device, then:
setup some appropriate class installer parameters so I can use SetupDiCallClassInstaller DIF_INSTALLDEVICE- to do the rest of the installation work.

Like I said, a sketch- I’ll add that where I usually go wrong when first working through these is knowing when to call the class installer and when to bypass it and go directly to the API. I don’t find it always intuitive whom does what to whom [and the installer is a black box, after all], although it usually doesn’t take too long to sort out once things are rolling and going every which way.


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

Mark,

Not answering for Bob of course :wink:

Did you specify the flag SPDIT_COMPATDRIVER in the call to
SetupDiBuildDriverInfoList() and specify a DeviceInfoData set?

Also, since you know the INF you want to install from, did you specify that
in the SP_DEVINSTALL_PARAMS with flags DI_ENUMSINGLEINF and
DI_FLAGSEX_ALLOWEXCLUDEDDRVS | DI_FLAGSEX_FILTERSIMILARDRIVERS?

In your case I wonder if the HWID match is only partial and thus the majik
might be the DI_FLAGSEX_FILTERSIMILARDRIVERS

And hopefully when the sun rises over Redmond, Bob will give the real
answer.

Good Luck,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Friday, October 15, 2010 9:10 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

Hi Bob, I have a question. I did do the steps you have listed here,
but I must be missing something. When I did the
setupdiBuildDriverInfoList and then call setupdiEnumDriverInfo, I only get
the driver that is loaded, I don’t get the drivers that are listed in the
INF file also. Am I missing something here?

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Thursday, October 14, 2010 6:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

With some hesitancy as this may not be helpful, and it probably sounds
terribly un-Microsoft:

I’m facing this same basic problem, and this is a basic sketch of how I
intend to approach it, based upon previous work I’ve done of this sort. But
not having completed this task, I can’t tell you what rough edges remain in
this sketch (this assumes the INF with your legacy driver is already known
to the system):

Get one or more SP_DEVINFO_DATA’s for the specific device(s) to update this
way [I thought I’d leave the details of how out for now, a lot of people know them], then for each one:

SetupDiBuildDriverIntoList- get a list of all the compatible drivers
SetupDiEnumDriverInfo- go through that list until I find the driver I want
to force, then:
SetupDiSetSelectedDriver- to force that to be the driver selected for that
device, then:
setup some appropriate class installer parameters so I can use
SetupDiCallClassInstaller DIF_INSTALLDEVICE- to do the rest of the
installation work.

Like I said, a sketch- I’ll add that where I usually go wrong when first
working through these is knowing when to call the class installer and when
to bypass it and go directly to the API. I don’t find it always intuitive
whom does what to whom [and the installer is a black box, after all],
although it usually doesn’t take too long to sort out once things are
rolling and going every which way.


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


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

Hi Dave,
I am pretty sure I tried SPDIT_COMPATDRIVER, but I will retry everything
with your suggestions…

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Friday, October 15, 2010 9:25 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

Mark,

Not answering for Bob of course :wink:

Did you specify the flag SPDIT_COMPATDRIVER in the call to
SetupDiBuildDriverInfoList() and specify a DeviceInfoData set?

Also, since you know the INF you want to install from, did you specify that
in the SP_DEVINSTALL_PARAMS with flags DI_ENUMSINGLEINF and
DI_FLAGSEX_ALLOWEXCLUDEDDRVS | DI_FLAGSEX_FILTERSIMILARDRIVERS?

In your case I wonder if the HWID match is only partial and thus the majik
might be the DI_FLAGSEX_FILTERSIMILARDRIVERS

And hopefully when the sun rises over Redmond, Bob will give the real
answer.

Good Luck,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Friday, October 15, 2010 9:10 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

Hi Bob, I have a question. I did do the steps you have listed here,
but I must be missing something. When I did the
setupdiBuildDriverInfoList and then call setupdiEnumDriverInfo, I only get
the driver that is loaded, I don’t get the drivers that are listed in the
INF file also. Am I missing something here?

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Thursday, October 14, 2010 6:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a
particular driver

With some hesitancy as this may not be helpful, and it probably sounds
terribly un-Microsoft:

I’m facing this same basic problem, and this is a basic sketch of how I
intend to approach it, based upon previous work I’ve done of this sort. But
not having completed this task, I can’t tell you what rough edges remain in
this sketch (this assumes the INF with your legacy driver is already known
to the system):

Get one or more SP_DEVINFO_DATA’s for the specific device(s) to update this
way [I thought I’d leave the details of how out for now, a lot of people know them], then for each one:

SetupDiBuildDriverIntoList- get a list of all the compatible drivers
SetupDiEnumDriverInfo- go through that list until I find the driver I want
to force, then:
SetupDiSetSelectedDriver- to force that to be the driver selected for that
device, then:
setup some appropriate class installer parameters so I can use
SetupDiCallClassInstaller DIF_INSTALLDEVICE- to do the rest of the
installation work.

Like I said, a sketch- I’ll add that where I usually go wrong when first
working through these is knowing when to call the class installer and when
to bypass it and go directly to the API. I don’t find it always intuitive
whom does what to whom [and the installer is a black box, after all],
although it usually doesn’t take too long to sort out once things are
rolling and going every which way.


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


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


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

Hi Dave,
I am pretty sure that I tried it with SPDIT_COMPATDRIVER, but I will retry everything with your suggestions…

–Mark

Ignore the message from my other gmail account… brain fart…

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Friday, October 15, 2010 9:25 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

Mark,

Not answering for Bob of course :wink:

Did you specify the flag SPDIT_COMPATDRIVER in the call to
SetupDiBuildDriverInfoList() and specify a DeviceInfoData set?

Also, since you know the INF you want to install from, did you specify that in the SP_DEVINSTALL_PARAMS with flags DI_ENUMSINGLEINF and DI_FLAGSEX_ALLOWEXCLUDEDDRVS | DI_FLAGSEX_FILTERSIMILARDRIVERS?

In your case I wonder if the HWID match is only partial and thus the majik might be the DI_FLAGSEX_FILTERSIMILARDRIVERS

And hopefully when the sun rises over Redmond, Bob will give the real answer.

Good Luck,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Friday, October 15, 2010 9:10 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

Hi Bob, I have a question. I did do the steps you have listed here,
but I must be missing something. When I did the
setupdiBuildDriverInfoList and then call setupdiEnumDriverInfo, I only get the driver that is loaded, I don’t get the drivers that are listed in the
INF file also. Am I missing something here?

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Thursday, October 14, 2010 6:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

With some hesitancy as this may not be helpful, and it probably sounds terribly un-Microsoft:

I’m facing this same basic problem, and this is a basic sketch of how I intend to approach it, based upon previous work I’ve done of this sort. But not having completed this task, I can’t tell you what rough edges remain in this sketch (this assumes the INF with your legacy driver is already known to the system):

Get one or more SP_DEVINFO_DATA’s for the specific device(s) to update this way [I thought I’d leave the details of how out for now, a lot of people know them], then for each one:

SetupDiBuildDriverIntoList- get a list of all the compatible drivers
SetupDiEnumDriverInfo- go through that list until I find the driver I want to force, then:
SetupDiSetSelectedDriver- to force that to be the driver selected for that device, then:
setup some appropriate class installer parameters so I can use SetupDiCallClassInstaller DIF_INSTALLDEVICE- to do the rest of the installation work.

Like I said, a sketch- I’ll add that where I usually go wrong when first working through these is knowing when to call the class installer and when to bypass it and go directly to the API. I don’t find it always intuitive whom does what to whom [and the installer is a black box, after all], although it usually doesn’t take too long to sort out once things are rolling and going every which way.


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


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


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

Please forgive me for being a little numb here, but I don’t see how you can build a DriverInfoList for devices contained within the INF file. To me it seems like SetupDiBuildDriverInfoList only builds a list for drivers that are currently loaded.

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Friday, October 15, 2010 9:25 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

Mark,

Not answering for Bob of course :wink:

Did you specify the flag SPDIT_COMPATDRIVER in the call to
SetupDiBuildDriverInfoList() and specify a DeviceInfoData set?

Also, since you know the INF you want to install from, did you specify that in the SP_DEVINSTALL_PARAMS with flags DI_ENUMSINGLEINF and DI_FLAGSEX_ALLOWEXCLUDEDDRVS | DI_FLAGSEX_FILTERSIMILARDRIVERS?

In your case I wonder if the HWID match is only partial and thus the majik might be the DI_FLAGSEX_FILTERSIMILARDRIVERS

And hopefully when the sun rises over Redmond, Bob will give the real answer.

Good Luck,
Dave Cattley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Friday, October 15, 2010 9:10 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

Hi Bob, I have a question. I did do the steps you have listed here,
but I must be missing something. When I did the
setupdiBuildDriverInfoList and then call setupdiEnumDriverInfo, I only get the driver that is loaded, I don’t get the drivers that are listed in the
INF file also. Am I missing something here?

–Mark

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bob Kjelgaard
Sent: Thursday, October 14, 2010 6:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

With some hesitancy as this may not be helpful, and it probably sounds terribly un-Microsoft:

I’m facing this same basic problem, and this is a basic sketch of how I intend to approach it, based upon previous work I’ve done of this sort. But not having completed this task, I can’t tell you what rough edges remain in this sketch (this assumes the INF with your legacy driver is already known to the system):

Get one or more SP_DEVINFO_DATA’s for the specific device(s) to update this way [I thought I’d leave the details of how out for now, a lot of people know them], then for each one:

SetupDiBuildDriverIntoList- get a list of all the compatible drivers
SetupDiEnumDriverInfo- go through that list until I find the driver I want to force, then:
SetupDiSetSelectedDriver- to force that to be the driver selected for that device, then:
setup some appropriate class installer parameters so I can use SetupDiCallClassInstaller DIF_INSTALLDEVICE- to do the rest of the installation work.

Like I said, a sketch- I’ll add that where I usually go wrong when first working through these is knowing when to call the class installer and when to bypass it and go directly to the API. I don’t find it always intuitive whom does what to whom [and the installer is a black box, after all], although it usually doesn’t take too long to sort out once things are rolling and going every which way.


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


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


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

I share your sense of numbness whenever I try to read the SetupDi
documentation to gather any useful insight. I am sure it makes sense to
*somebody*.

When you call SetupDiBuildDriverInfoList() you can pass it a DeviceInfoData
structure. That DeviceInfoData structure in this case we want to be the
DeviceInfoData for the device you are trying to update the driver for.

One of the things you can do *to* that DeviceInfoData is to call
SetupDiSetDeviceInstallParams() to modify the SP_DEVICEINSTALL_PARAMS Flags,
FlagsEx, and DriverPath.

If you do a SetupDiGetDeviceInstallParams() to get the current values and
then modify them by setting

DriverPath to your INF file
Flags |= DI_ENUMSINGLEINF
FlagsEx |= DIF_FLAGSEX_ALLOWEXCLUDEDDRVS | DIF_FLAGSEX_FILTERSIMILARDRIVERS

Then call SetupDiSetDeviceInstallParams() to set those values back.

Then call SetupDiBuildDriverInfoList() and specify the DeviceInfoData for
that device.

And maybe SetupDi will play along and load the driver data only for your
driver.

And if you tried all that and I am just not understanding your current state
of affairs, I would conclude I have no idea what to do next.

I hope this helps.

Cheers,
Dave Cattley

Below is the code I am working with. The problem I am having is that I am getting back 0xe000020a from the line with **** after it. That is what I am exploring now… BTW, what the heck is 0xe000020a?

int Replace1394BusDriver()
{
DWORD Err = NO_ERROR;
HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVINFO_DATA DeviceInfoData1;
DWORD Reboot = false;
int result = EXIT_FAIL;
DWORD memberIndex = 0;
SP_DEVINSTALL_PARAMS installParams;

memset(&installParams,0,sizeof(installParams));

DebugBreak();
//
// Create an empty device information list.
//
DeviceInfoSet = SetupDiGetClassDevsEx(&GUID_DEVCLASS_1394,NULL,NULL,DIGCF_PRESENT,NULL,NULL,NULL);
if (DeviceInfoSet == INVALID_HANDLE_VALUE) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if(!SetupDiEnumDeviceInfo(DeviceInfoSet,0,&DeviceInfoData)) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

//
// We got information about a member in the 1394 class, let’s
// see if it is the legacy driver.
//
DumpDevice(DeviceInfoSet,&DeviceInfoData);

installParams.cbSize = sizeof(installParams);
installParams.Flags = DI_ENUMSINGLEINF;
installParams.FlagsEx = DI_FLAGSEX_ALLOWEXCLUDEDDRVS | DI_FLAGSEX_FILTERSIMILARDRIVERS;

if(!SetupDiSetDeviceInstallParams(DeviceInfoSet,&DeviceInfoData,&installParams)) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

if(!SetupDiBuildDriverInfoList(DeviceInfoSet,&DeviceInfoData,SPDIT_COMPATDRIVER)) { ******
Err = GetLastError();
goto Replace1394BusDriverExit;
}

while(TRUE) {
DeviceInfoData1.cbSize = sizeof(DeviceInfoData1);
if(!SetupDiEnumDeviceInfo(DeviceInfoSet,memberIndex,&DeviceInfoData1)) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

DumpDevice(DeviceInfoSet,&DeviceInfoData1);

memberIndex++;
}

Replace1394BusDriverExit:
return result;

}
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Friday, October 15, 2010 10:40 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

I share your sense of numbness whenever I try to read the SetupDi documentation to gather any useful insight. I am sure it makes sense to *somebody*.

When you call SetupDiBuildDriverInfoList() you can pass it a DeviceInfoData
structure. That DeviceInfoData structure in this case we want to be the
DeviceInfoData for the device you are trying to update the driver for.

One of the things you can do *to* that DeviceInfoData is to call
SetupDiSetDeviceInstallParams() to modify the SP_DEVICEINSTALL_PARAMS Flags, FlagsEx, and DriverPath.

If you do a SetupDiGetDeviceInstallParams() to get the current values and then modify them by setting

DriverPath to your INF file
Flags |= DI_ENUMSINGLEINF
FlagsEx |= DIF_FLAGSEX_ALLOWEXCLUDEDDRVS | DIF_FLAGSEX_FILTERSIMILARDRIVERS

Then call SetupDiSetDeviceInstallParams() to set those values back.

Then call SetupDiBuildDriverInfoList() and specify the DeviceInfoData for that device.

And maybe SetupDi will play along and load the driver data only for your driver.

And if you tried all that and I am just not understanding your current state of affairs, I would conclude I have no idea what to do next.

I hope this helps.

Cheers,
Dave Cattley


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, I got farther. The one change that I made was to add

wcscpy_s(installParams.DriverPath,SIZECHARS(installParams.DriverPath),
TEXT(“C:\WINDOWS\INF\1394.INF”));

To tell it exactly which INF file I wanted. However, with that change I only seem to have 1 device in my built list… Off to figure that out. Did I mentioned that this sucks…

Thanks to all for being patient… Now I know why I stick to drivers…

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Friday, October 15, 2010 11:06 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

Below is the code I am working with. The problem I am having is that I am getting back 0xe000020a from the line with **** after it. That is what I am exploring now… BTW, what the heck is 0xe000020a?

int Replace1394BusDriver()
{
DWORD Err = NO_ERROR;
HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA DeviceInfoData;
SP_DEVINFO_DATA DeviceInfoData1;
DWORD Reboot = false;
int result = EXIT_FAIL;
DWORD memberIndex = 0;
SP_DEVINSTALL_PARAMS installParams;

memset(&installParams,0,sizeof(installParams));

DebugBreak();
//
// Create an empty device information list.
//
DeviceInfoSet = SetupDiGetClassDevsEx(&GUID_DEVCLASS_1394,NULL,NULL,DIGCF_PRESENT,NULL,NULL,NULL);
if (DeviceInfoSet == INVALID_HANDLE_VALUE) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if(!SetupDiEnumDeviceInfo(DeviceInfoSet,0,&DeviceInfoData)) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

//
// We got information about a member in the 1394 class, let’s
// see if it is the legacy driver.
//
DumpDevice(DeviceInfoSet,&DeviceInfoData);

installParams.cbSize = sizeof(installParams);
installParams.Flags = DI_ENUMSINGLEINF;
installParams.FlagsEx = DI_FLAGSEX_ALLOWEXCLUDEDDRVS | DI_FLAGSEX_FILTERSIMILARDRIVERS;

if(!SetupDiSetDeviceInstallParams(DeviceInfoSet,&DeviceInfoData,&installParams)) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

if(!SetupDiBuildDriverInfoList(DeviceInfoSet,&DeviceInfoData,SPDIT_COMPATDRIVER)) { ******
Err = GetLastError();
goto Replace1394BusDriverExit;
}

while(TRUE) {
DeviceInfoData1.cbSize = sizeof(DeviceInfoData1);
if(!SetupDiEnumDeviceInfo(DeviceInfoSet,memberIndex,&DeviceInfoData1)) {
Err = GetLastError();
goto Replace1394BusDriverExit;
}

DumpDevice(DeviceInfoSet,&DeviceInfoData1);

memberIndex++;
}

Replace1394BusDriverExit:
return result;

}
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Friday, October 15, 2010 10:40 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How do you programmatically force setupdi to load a particular driver

I share your sense of numbness whenever I try to read the SetupDi documentation to gather any useful insight. I am sure it makes sense to *somebody*.

When you call SetupDiBuildDriverInfoList() you can pass it a DeviceInfoData
structure. That DeviceInfoData structure in this case we want to be the
DeviceInfoData for the device you are trying to update the driver for.

One of the things you can do *to* that DeviceInfoData is to call
SetupDiSetDeviceInstallParams() to modify the SP_DEVICEINSTALL_PARAMS Flags, FlagsEx, and DriverPath.

If you do a SetupDiGetDeviceInstallParams() to get the current values and then modify them by setting

DriverPath to your INF file
Flags |= DI_ENUMSINGLEINF
FlagsEx |= DIF_FLAGSEX_ALLOWEXCLUDEDDRVS | DIF_FLAGSEX_FILTERSIMILARDRIVERS

Then call SetupDiSetDeviceInstallParams() to set those values back.

Then call SetupDiBuildDriverInfoList() and specify the DeviceInfoData for that device.

And maybe SetupDi will play along and load the driver data only for your driver.

And if you tried all that and I am just not understanding your current state of affairs, I would conclude I have no idea what to do next.

I hope this helps.

Cheers,
Dave Cattley


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


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