【问题标题】:Windows Driver : Install legacy hardware with command line toolWindows 驱动程序:使用命令行工具安装旧版硬件
【发布时间】:2019-05-20 16:56:04
【问题描述】:

操作系统:Windows Server 2016 R2

我有一个 RAMDisk 驱动程序可以使用“添加旧硬件向导”(hdwwiz.exe)成功安装。从devcon hwids *的输出可以看出设备如下。

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

但是,我需要通过 Ansible 完成安装,因此无法使用 hdwwiz.exe。它必须通过命令行完成,无需交互。

我尝试了几种方法,但都没有奏效。


方法一: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\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.

这是来自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)]

方法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

成功了,但实际上驱动没有安装。


它们都不起作用。 DpInst.exe 说No matching devices found in INF,DevCon.exe 说Unable to find any matching devices。似乎是同一个原因。

但是驱动可以用hdwwiz.exe手动安装,有谁知道hdwwiz.exe里面的秘密是什么?

【问题讨论】:

    标签: driver setupapi devcon


    【解决方案1】:

    不能使用 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 文件中查找它并使用正确的部分(在我的示例中为“Yubico64_Install.NT”)。使用错误的部分不会提示错误。在我的示例中,我使用安静模式、无 UI (4) 和永不重启 (N) 来通过 GPO 自动安装驱动程序。所有选项都在此处详细记录:

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

    【讨论】:

      猜你喜欢
      • 2014-04-25
      • 2023-04-03
      • 2020-06-17
      • 2018-02-27
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多