Windows 驱动程序:使用命令行工具安装旧硬件
Windows Driver : Install legacy hardware with command line tool
操作系统:WindowsServer 2016 R2
我有一个 RAMDisk 驱动可以用 "Add Legacy Hardware Wizard" (hdwwiz.exe) 安装成功。从devcon hwids *
的输出可以看出设备如下。
ROOT\UNKNOWN[=11=]00
Name: RAMDrive [ QSoft ] Enterprise (x64)
Hardware IDs:
ramdriv
但是,我需要通过Ansible完成安装,因此hdwwiz.exe
无法使用。它必须通过命令行完成,无需交互。
我尝试了几种方法,其中 none 行得通。
方法一:DevCon.exe(Windows 设备控制台)
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[=12=]00
Device node created. Install is complete when drivers are installed...
Updating drivers for ROOT\UNKNOWN[=12=]00 from C:\Ramdisk64_inst\RAMDriv.inf.
devcon.exe failed.
这是来自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[=13=]00]
>>> Section start 2018/12/20 07:11:50.687
cmd: devcon.exe install RAMDriv.inf ROOT\UNKNOWN[=13=]00
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)]
方法 2:DPInst.exe(驱动程序包安装程序)
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
方法 3:rundll32 调用 SetupAPI
C:\Ramdisk64_inst>rundll32.exe setupapi.dll,InstallHinfSection DiskInstall 128 C:\Ramdisk64_inst\RAMDriv.inf
无报错结束,但驱动未安装
方法 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
成功了,但实际上没有安装驱动
None 其中有效。 DpInst.exe 表示 No matching devices found in INF
,DevCon.exe 表示 Unable to find any matching devices
。好像也是这个道理。
不过驱动可以用hdwwiz.exe
手动安装,有谁知道hdwwiz.exe
里面的秘密是什么?
旧版驱动程序无法使用 pnputil 安装,必须使用 LaunchINFSectionEx-Call
我测试了以下内容,它适用于从 Windows 2000 到 Windows 10、2012R2、2016、2019 的多个驱动程序。
rundll32.exe advpack.dll,LaunchINFSectionEx ykmd.inf,Yubico64_Install.NT,,4,N
注意正确使用段落
当没有 [DefaultInstall]-Section 时,必须使用 inf-File 的正确部分。大多数答案都缺少这一点。在您的驱动程序中查找 inf-File 和 使用正确的部分 (在我的示例中 "Yubico64_Install.NT")。使用错误的部分不会提示错误。在我的示例中,我使用安静模式、无 UI (4) 和永不重启 (N) 来通过 GPO 自动安装驱动程序。此处详细记录了所有选项:
操作系统:WindowsServer 2016 R2
我有一个 RAMDisk 驱动可以用 "Add Legacy Hardware Wizard" (hdwwiz.exe) 安装成功。从devcon hwids *
的输出可以看出设备如下。
ROOT\UNKNOWN[=11=]00
Name: RAMDrive [ QSoft ] Enterprise (x64)
Hardware IDs:
ramdriv
但是,我需要通过Ansible完成安装,因此hdwwiz.exe
无法使用。它必须通过命令行完成,无需交互。
我尝试了几种方法,其中 none 行得通。
方法一:DevCon.exe(Windows 设备控制台)
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[=12=]00
Device node created. Install is complete when drivers are installed...
Updating drivers for ROOT\UNKNOWN[=12=]00 from C:\Ramdisk64_inst\RAMDriv.inf.
devcon.exe failed.
这是来自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[=13=]00]
>>> Section start 2018/12/20 07:11:50.687
cmd: devcon.exe install RAMDriv.inf ROOT\UNKNOWN[=13=]00
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)]
方法 2:DPInst.exe(驱动程序包安装程序)
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
方法 3:rundll32 调用 SetupAPI
C:\Ramdisk64_inst>rundll32.exe setupapi.dll,InstallHinfSection DiskInstall 128 C:\Ramdisk64_inst\RAMDriv.inf
无报错结束,但驱动未安装
方法 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
成功了,但实际上没有安装驱动
None 其中有效。 DpInst.exe 表示 No matching devices found in INF
,DevCon.exe 表示 Unable to find any matching devices
。好像也是这个道理。
不过驱动可以用hdwwiz.exe
手动安装,有谁知道hdwwiz.exe
里面的秘密是什么?
旧版驱动程序无法使用 pnputil 安装,必须使用 LaunchINFSectionEx-Call
我测试了以下内容,它适用于从 Windows 2000 到 Windows 10、2012R2、2016、2019 的多个驱动程序。
rundll32.exe advpack.dll,LaunchINFSectionEx ykmd.inf,Yubico64_Install.NT,,4,N
注意正确使用段落
当没有 [DefaultInstall]-Section 时,必须使用 inf-File 的正确部分。大多数答案都缺少这一点。在您的驱动程序中查找 inf-File 和 使用正确的部分 (在我的示例中 "Yubico64_Install.NT")。使用错误的部分不会提示错误。在我的示例中,我使用安静模式、无 UI (4) 和永不重启 (N) 来通过 GPO 自动安装驱动程序。此处详细记录了所有选项: