Programmatically install "non compatible" driver - windows

I want to install signed driver but unfortunately the .inf file does not contain the correct hardware IDs. (incompatible driver)
I can install the driver manually like described here:
Force installing incompatible .inf driver in Windows Server 2019 Core
Right Click Update Driver in Device Manager
"Browse my computer for computer software”
“Let me pick from a list of available drivers on my computer”
Select “Have Disk…” and point to the driver folder
Now I'm looking for a way to do the same from script or code.
What I've tried so far:
I've tried to install the driver with devcon install -r <inf file> <device id> without success (error without any log).
patching the inf file with hardware Ids would break the driver signature and this is therefore not a good solution
PnPUtil: This adds the driver to the driver store, but because it is not compatible, the driver is not installed
It would also help to have answers or comments to the following questions:
Where can i get more logs from devcon to see detailed error descriptions
Can I somehow sign the driver by my self after patching the inf file?
Any other Ideas what i could try?

Related

Installing a driver for a specific device

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, 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.)

How to install WinUSB driver through customized inf file on Windows 10?

I need to communicate with a simple custom device directly through USB. I have full specifications for communication protocol. Unfortunately, the device vendor did not provide WinUSB driver for the device.
According to
https://msdn.microsoft.com/en-us/library/ff540283.aspx#inf
I should be able to install WinUSB driver automatically on Windows 10 using the inf template.
But installation fails with:
The third-party INF does not contain digital signature information.
As I understand, it is looking for a signed .cat file. But in this case I have no any files to sign nor .cat file. I just want to install Windows own WinUSB driver for the device, and clearly Windows drivers should be signed by Microsoft.
How do I proceed to install the .inf file?
If you only care about supporting Windows 8.1 and later, and you have the ability to change the device's firmware, you might consider using Micrsoft OS 2.0 Descriptors. This will allow a Windows computer to recognize the device as a WinUSB device and automatically load the WinUSB driver.
Another option would be to use Zadig or the related library libwdi to install the driver for your device. I would only recommend this for small, temporary, or organization-internal installations since it is kind of a hack (it installs its own certificate into your Trusted Root Certification Authorities list).
You could also look into disabling driver signature enforcement on your computer if you want to use the unsigned INF file.
If none of those options are going to work for you, then you need to look into buying a code-signing certificate from a certificate authority and signing your driver. Code signing for Windows is an ever-evolving field but my article Practical Windows Code and Driver Signing attempts to document what you need to know.

Is it possible to fully install a driver when the device is not present?

Is it possible to fully install (and not just pre-install) a device driver on a system before the physical device is plugged in? In particular, I'm looking at the D2XX drivers by FTDI. Their driver installation program effectively runs dpinst.exe, and if you watch the console output of that program it says this:
No matching device was found for 'c:\drivers\ftdiport.inf'. Driver will be installed when plugged in.
The trouble is that I'm also using their .NET library for accessing the device, and that library is funny. It pops up an alert in the constructor if the driver isn't installed. Of course the usual solution is to simply plug in the device and let the driver installation finish as normal, but sometimes this is neglected. The pitfalls with having an unavoidable popup box in a 3rd party library should be obvious.
So does anyone know of a way to automate the full installation, and not just the pre-installation? Are there any dangers to copying the driver to the system folder manually / in advance?
You seem to mention "fully install" by "staging" the driver not by "loading" the driver. You can refer to the source code of "devcon.exe" for dp_add command, which actually do staging the driver package. Staged driver package will be being searched by PnP Manager when the unknown device is detected.

Windows Virtual (fake) Device INF installation

I have been trying to install the MSVAD virtual audio sample drivers from the Windows DDK on Windows 7 64bits, without success.
I modified the sample INF to only support the "simple" driver. The ChkInf tool confirms that everything is OK with the INF file, I signed the package with a Test certificate. So far, so good.
The problem is: despite reading the documentation on the Microsoft website, I have no clue of how to actually install this driver. The problem is that it does not match a physical device, so I can't use the Device Manager to update the driver on an existing device.
Aside from that, the right-click on INF + Install method does not work as the INF lacks a DefaultInstall section (which is a requirement for signing drivers).
I would like to be able to install this driver from the command-line ideally, but if a specific program is required, I'll have to go that way.
Thanks in advance for any clue on how to solve this.
Well, I guess I hadn't searched far enough: http://social.msdn.microsoft.com/Forums/en-US/windowspro-audiodevelopment/thread/68ac63f3-7bb1-45b0-9677-957d7aa9f2d9

Forcing Windows to re-scan for drivers

As part of our software's installation, we install drivers for a required 3rd party hardware component. Currently it's up to the user to manually scan for their hardware's drivers once our installation is completed.
Is there an easy way to get Windows to automatically look for the drivers we installed? If so, how does it work? Do we need to tell the OS for which hardware device we have drivers, or just that we have drivers in a certain location? Or can we just install the drivers to System32 folder and trigger a driver rescan?
So the hardware is already plugged in when you install the driver?
Download the Windows Driver Kit (WDK) and see the devcon sample (binary and source included). The "devcon update" command should do what you want (i.e. install the drivers and then load them over the specified device instance).
-scott

Resources