I would like to install a custom driver for a specific device in my machine programmatically:
- The driver comes as an .inf file (with some other files as well).
- The device is one of two identical network adapters in my computer.
As far as I know the only way to achieve this goal is to use the Microsoft Setup API. From reading the documentation I would assume that I need to perform two steps:
- Use "DiInstallDriver" to install my .inf-based driver into the driver store (see https://learn.microsoft.com/en-us/windows/win32/api/newdev/nf-newdev-diinstalldrivera).
- Use "DiInstallDevice" to apply my driver to the device (see https://learn.microsoft.com/en-us/windows/win32/api/newdev/nf-newdev-diinstalldevice).
Would this be the correct/easiest way to do this?
If so, here's a follow up question: DiInstallDevice requires two parameters which I don't know how to acquire:
- DeviceInfoData: this should point to the network adapter I want to modify. How do I get this?
- DriverInfoData: this should probably point to the driver I installed in step 1? How do I get this?
PS: Doing all this manually is uper easy: Open device manager, right-click the network adapter, select 'Update driver', choose .imf file from disk -> done! But in this case I need to do it programmatically.
PPS: DevCon is not an option. It only allows to exchange the driver based on an Hardware ID. And that ID is the same for both of my network adapters (since they are exactly identical). So it would change the driver both devices.
You don’t need to call two methods,
DiInstallDrivernot only preinstalls a driver in the driver store, but also installs the driver on devices present in the system that the driver supports.You can refer to the following documents: Functions that Simplify Driver Installation It seems that
UpdateDriverForPlugAndPlayDevicesis the simplest way.For
DiInstallDevice, this function should only be use if both of the following are true:You can specify the
HardwareIdof network adapter for theUpdateDriverForPlugAndPlayDevices. If you want to install your .inf driver no matter what a better driver already exists on your computer, you also need to specifyInstallFlagsasINSTALLFLAG_FORCE.(Caution: Forcing the installation of the driver can result in replacing a more compatible or newer driver with a less compatible or older driver.)