3
votes

I have a USB device that I use on Windows 7, 8, 8.1, and 10 machines. This device is (eventually) recognized by Windows Update on all these configurations, and a default driver is installed for the device. I would like to force this device to use a driver that I specify, which is not the default driver that Windows will select. I want to do this programmatically, preferably using components that are native to Windows (like batch or PowerShell), or are small enough that they could be included in a deployable installation package.

The goal is to find some programmatic way to replicate the functionality invoked by the following set of steps:

Open Device Manager --> Right-click on desired device to update --> "Update Driver Software..." --> "Browse My Computer For Driver Software" --> "Let Me Pick From A List Of Drivers On My Computer" --> Deselect "Show Compatible Hardware" checkbox --> Select manufacturer and model.

As far as I can tell, this effectively bypasses the default hardware IDs that are specified in the device's previously- or default-applied *.INF file.

I have tried performing this using devcon.exe (trying both the "install" and "update" functions), and found this to fail each time, no matter how generically I specified the device's hardware ID (without allowing it affecting other devices, of course). I can list the device's driver files, but cannot change them.

I also researched PnPUtil, but this does not appear to be suited for the application of applying a specific driver to a specific device.

Been poring over PowerShell's documentation, as well, and again can list the device and all of its properties (including it driver and driver files), but I have not yet found a way to forcibly, and programmatically, install the driver of my selection.

Any ideas on how to achieve the aforementioned goal? Thanks so much in advance.

2
What's with the downvote? - Dean Rusmor
Dean, did you managed to solve this? Can you post the solution? - StefanoV

2 Answers

0
votes

USB host (Windows) selects the suitable driver based on the descriptors the device returns when asked (in some cases the drivers are loaded per interface, in that case you need to read the interface descriptor). The device descriptor can contain following information:

bcdUSB
bDeviceClass
bDeviceSubClass
bDeviceProtocol
bMaxPacketSize0
idVendor
idProduct
bcdDevice
iManufacturer
iProduct
iSerialNumber
bNumConfigurations

The generic (default) class drivers are usually selected based on bDeviceClass, bDeviceSubclass and perhaps some other details. If the device vendor wants their driver to override the default driver, they implement an .inf file for idVendor and idProduct and make that point to their driver. That is what you should do if you want to override the default driver. I would say, even if you want to do it in the code, you need to generate that inf file. This is pretty good source of information, even if you are not implementing the driver yourself.

0
votes

If your device IS NOT plug and play and if it could be plugged into machine during operation, you could try to use DevCon and perform its Install and Update functions.