title: Windows Driver : Install legacy hardware with command line tool
body: <p>Operation System: Windows Server 2016 R2</p>
  
  <p>I have a RAMDisk driver can be installed with "Add Legacy Hardware Wizard" (hdwwiz.exe) successfully. From the output of <code>devcon hwids *</code>, the device can be seen as below.</p>
  
  <pre><code>ROOT\UNKNOWN\0000
      Name: RAMDrive [ QSoft ] Enterprise (x64)
      Hardware IDs:
          ramdriv
  </code></pre>
  
  <p>However, I need complete the installation via Ansible, hence <code>hdwwiz.exe</code> cannot be used. It has to be done via command line without interaction.</p>
  
  <p>I tried several approaches and none of them works.</p>
  
  <hr>
  
  <h3>Approach I : DevCon.exe (Windows Device Console)</h3>
  
  <pre><code>C:\Ramdisk64_inst&gt;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&gt;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.
  </code></pre>
  
  <p>Here is the log from <code>C:\Windows\INF\setupapi.dev.log</code></p>
  
  <pre><code>&gt;&gt;&gt;  [Device Install (UpdateDriverForPlugAndPlayDevices) - ramdriv]
  &gt;&gt;&gt;  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.
  &lt;&lt;&lt;  Section end 2018/12/20 07:10:35.717
  &lt;&lt;&lt;  [Exit status: FAILURE(0xe000020b)]
  
  
  &gt;&gt;&gt;  [Device Install (UpdateDriverForPlugAndPlayDevices) - ROOT\UNKNOWN\0000]
  &gt;&gt;&gt;  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.
  &lt;&lt;&lt;  Section end 2018/12/20 07:11:50.734
  &lt;&lt;&lt;  [Exit status: FAILURE(0xe000020b)]
  </code></pre>
  
  <hr>
  
  <h3>Approach 2 : DPInst.exe (Driver Package Installer)</h3>
  
  <pre><code>C:\Ramdisk64_inst&gt;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
  </code></pre>
  
  <hr>
  
  <h3>Approach 3 : rundll32 calls SetupAPI</h3>
  
  <pre><code>C:\Ramdisk64_inst&gt;rundll32.exe setupapi.dll,InstallHinfSection DiskInstall 128 C:\Ramdisk64_inst\RAMDriv.inf
  </code></pre>
  
  <p>It ends without any error, but the driver is not installed.</p>
  
  <hr>
  
  <h3>Approach 4 : PnPUtil</h3>
  
  <pre><code>C:\Ramdisk64_inst&gt;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
  </code></pre>
  
  <p>It succeeded, but in fact driver is not installed.</p>
  
  <hr>
  
  <p>None of them works. DpInst.exe says <code>No matching devices found in INF</code>, DevCon.exe says <code>Unable to find any matching devices</code>. It seems the same reason.</p>
  
  <p>However the driver can be installed with <code>hdwwiz.exe</code> manually, does anyone know what is the secret inside <code>hdwwiz.exe</code>?  </p>