Windows Driver : Install legacy hardware with command line tool

1

Operation System: Windows Server 2016 R2

I have a RAMDisk driver can be installed with "Add Legacy Hardware Wizard" (hdwwiz.exe) successfully. From the output of devcon hwids *, the device can be seen as below.

ROOT\UNKNOWN\0000
    Name: RAMDrive [ QSoft ] Enterprise (x64)
    Hardware IDs:
        ramdriv

However, I need complete the installation via Ansible, hence hdwwiz.exe cannot be used. It has to be done via command line without interaction.

I tried several approaches and none of them works.


Approach I : DevCon.exe (Windows Device Console)

C:\Ramdisk64_inst>devcon.exe install RAMDriv.inf ramdriv

Device node created. Install is complete when drivers are installed...
Updating drivers for ramdriv from C:\Ramdisk64_inst\RAMDriv.inf.
devcon.exe failed.

C:\Ramdisk64_inst>devcon.exe install RAMDriv.inf ROOT\UNKNOWN\0000

Device node created. Install is complete when drivers are installed...
Updating drivers for ROOT\UNKNOWN\0000 from C:\Ramdisk64_inst\RAMDriv.inf.
devcon.exe failed.

Here is the log from C:\Windows\INF\setupapi.dev.log

>>>  [Device Install (UpdateDriverForPlugAndPlayDevices) - ramdriv]
>>>  Section start 2018/12/20 07:10:35.670
      cmd: C:\Ramdisk64_inst\devcon.exe  install C:\Ramdisk64_inst\RAMDriv.inf ramdriv
     ndv: INF path: C:\Ramdisk64_inst\RAMDriv.inf
     ndv: Install flags: 0x00000001
!    ndv: Unable to find any matching devices.
<<<  Section end 2018/12/20 07:10:35.717
<<<  [Exit status: FAILURE(0xe000020b)]


>>>  [Device Install (UpdateDriverForPlugAndPlayDevices) - ROOT\UNKNOWN\0000]
>>>  Section start 2018/12/20 07:11:50.687
      cmd: devcon.exe  install RAMDriv.inf ROOT\UNKNOWN\0000
     ndv: INF path: C:\Ramdisk64_inst\RAMDriv.inf
     ndv: Install flags: 0x00000001
!    ndv: Unable to find any matching devices.
<<<  Section end 2018/12/20 07:11:50.734
<<<  [Exit status: FAILURE(0xe000020b)]

Approach 2 : DPInst.exe (Driver Package Installer)

C:\Ramdisk64_inst>dpinst.exe /PATH C:\Ramdisk64_inst /Q /C /LM

INFO:   Option set: dumping log info to console.
INFO:   Current working directory: 'C:\Ramdisk64_inst'
INFO:   Running on path 'C:\Ramdisk64_inst'
INFO:   No valid 'dpinst.xml' file provided.
INFO:   Install option set: Running in quiet mode. Suppressing Wizard and OS popups.
INFO:   Install option set: legacy mode on.
INFO:   Found driver package: 'C:\Ramdisk64_inst\RAMDriv.inf'.
INFO:   Preinstalling 'c:\ramdisk64_inst\ramdriv.inf' ...
INFO:   ENTER:  DriverPackagePreinstallW
INFO:   Driver package is already preinstalled 'c:\ramdisk64_inst\ramdriv.inf'.
SUCCESS:c:\ramdisk64_inst\ramdriv.inf is preinstalled.
INFO:   RETURN: DriverPackagePreinstallW  (0xB7)
INFO:   ENTER:  DriverPackageGetPathW
INFO:   RETURN: DriverPackageGetPathW  (0x0)
INFO:   ENTER:  DriverPackageInstallW
WARNING:DRIVER_PACKAGE_LEGACY_MODE flag set but not supported on Plug and Play driver on VISTA. Flag will be ignored.
INFO:   Installing INF file 'c:\ramdisk64_inst\ramdriv.inf' (Plug and Play).
INFO:   Looking for Model Section [DiskDevice.NTamd64]...
INFO:   No matching devices found in INF "C:\Windows\System32\DriverStore\FileRepository\ramdriv.inf_amd64_fcc99ac0622d865b\ramdriv.inf" on the Machine.
INFO:   No drivers installed. No devices found that match driver(s) contained in 'C:\Windows\System32\DriverStore\FileRepository\ramdriv.inf_amd64_fcc99ac0622d865b\ramdriv.inf'.
INFO:   RETURN: DriverPackageInstallW  (0xE000020B)
INFO:   No matching device was found for 'c:\ramdisk64_inst\ramdriv.inf'. Driver will be installed when plugged in.
INFO:   Returning with code 0x100

Approach 3 : rundll32 calls SetupAPI

C:\Ramdisk64_inst>rundll32.exe setupapi.dll,InstallHinfSection DiskInstall 128 C:\Ramdisk64_inst\RAMDriv.inf

It ends without any error, but the driver is not installed.


Approach 4 : PnPUtil

C:\Ramdisk64_inst>pnputil.exe /add-driver C:\Ramdisk64_inst\RAMDriv.inf /install /subdirs /restart

Microsoft PnP Utility

Adding driver package:  RAMDriv.inf
Driver package added successfully.
Published Name:         oem7.inf
Driver package installed on matching devices.

Total driver packages:  1
Added driver packages:  1

It succeeded, but in fact driver is not installed.


None of them works. DpInst.exe says No matching devices found in INF, DevCon.exe says Unable to find any matching devices. It seems the same reason.

However the driver can be installed with hdwwiz.exe manually, does anyone know what is the secret inside hdwwiz.exe?

driver
setupapi
devcon
asked on Stack Overflow Dec 20, 2018 by Mr.Wang from Next Door • edited Dec 20, 2018 by Mr.Wang from Next Door

1 Answer

2

Legacy Drivers canĀ“t be installed with pnputil and have to use LaunchINFSectionEx-Call

I tested the following and it works with several drivers from Windows 2000 up to Windows 10, 2012R2, 2016, 2019.

rundll32.exe advpack.dll,LaunchINFSectionEx ykmd.inf,Yubico64_Install.NT,,4,N

Pay attention to use the correct section

The correct section of the inf-File must be used, when there is no [DefaultInstall]-Section. This lacks in most answers. Look it up in your drivers inf-File and use the correct section (in my example "Yubico64_Install.NT"). Using the wrong section wont prompt an error. Im my example I use Quiet mode, no UI (4) and Never reboot (N) to install the driver automated via GPO. All options are documented in detail here:

https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa768006(v%3Dvs.85)

answered on Stack Overflow Jul 2, 2019 by x0nn • edited Jul 2, 2019 by x0nn

User contributions licensed under CC BY-SA 3.0