windowssetupapi

Change installed device driver


I am trying to change the installed driver for a device using SetupAPI. The driver is already present on the PC, just not currently selected.

More specifically, I am trying undo the installation of a third-party driver for a USB composite device, and install the default windows driver instead.

I already got it almost working like this: First, find the device using

SetupDiGetClassDevs
SetupDiEnumDeviceInfo
SetupDiGetDeviceInstanceId

to find the device.

Next, find the default USB composite device driver I want to install using

SetupDiBuildDriverInfoList
SetupDiEnumDriverInfo
SetupDiGetDriverInfoDetail

Once I found the driver, I call

SetupDiSetSelectedDriver
SetupDiInstallDevice

This actually does switch the driver back, as can be observed in device manager.

However, the third party driver put the device into its own group/category, and this change is not undone when using my approach.

Manually selecting the standard USB composite device driver in the device manager does restore the device category back to USB Controllers, which is why I think my driver installation process is incomplete. What might I be missing?


Solution

  • Turns out the working installation sequence is

    SetupDiSetSelectedDevice
    SetupDiSetSelectedDriver
    InstallSelectedDriver // From newdev.dll, not in a public header