0

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:

  1. 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).
  2. 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.

Botje
  • 26,269
  • 3
  • 31
  • 41
Boris
  • 8,551
  • 25
  • 67
  • 120

1 Answers1

0

You don’t need to call two methods, DiInstallDriver not 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 UpdateDriverForPlugAndPlayDevices is the simplest way.

For DiInstallDevice, this function should only be use if both of the following are true:

  • The application incorporates more than one device instance of the same type, that is, all the device instances have the same hardware IDs and compatible IDs.
  • The application requires that device-instance-specific drivers be installed on the device instances.

UpdateDriverForPlugAndPlayDevices or DiInstallDriver is the simplest way for an installation application to install a new driver that is the best match for devices in the system. ... The basic operation of UpdateDriverForPlugAndPlayDevices is similar to the operation of DiInstallDriver. However UpdateDriverForPlugAndPlayDevices supports additional installation options.

You can specify the HardwareId of network adapter for the UpdateDriverForPlugAndPlayDevices. If you want to install your .inf driver no matter what a better driver already exists on your computer, you also need to specify InstallFlags as INSTALLFLAG_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.)

Drake Wu
  • 6,927
  • 1
  • 7
  • 30