How to install drivers silently using MSI

In this blog post we will show following:

  • How to find drivers
  • What you will need to install drivers:
    • Driver files
    • DPInst.exe to install drivers (It usually can be found in Windows ADK or next to driver files)
    • Certificates – In cases where a window is shown with the option to always trust the publisher you will need to add a certificate. The easiest way to find them is using regedit, but there are other options too.
      • Path to Trusted Publisher certificates: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SystemCertificates\TrustedPublisher\Certificates
  • How to create Custom Actions for Installing Drivers using Master Packager
  • How to create Template for future use

How to find DPInst.exe and drivers

To locate DPInst.exe:

  1. Open Process Monitor. Stop the capture and clear data.
  2. Run installation
  3. When DPInst.exe install windows appears, start the capturing process and when it finishes stop the process
  4. Add a filter – Set the Category to write. Add it and click apply Adding Filter in Process Monitor
  5. Search for a process with a name like DPInst*.exe, right click and select “Jump to”
    Locating dpinst.exe location in Process Monitor

Note that the name of the executable can be slightly different. E.g.
DPINST.EXE, dpinst.x64.exe, dpinst-amd64.exe, dpinst-x86.exe,
DPInst32.exe etc.

Copy DPInst.exe to a new folder.

To locate driver files and registries:

  1. On clean VM open Master Repackager
  2. Create first snapshot
    Creating first snapshot in Master Repackager
  3. Run DPInst.exe
  4. After installation create second snapshot
    Saving system changes in Master Repackager
    Cleanup screen in Master Repackager
  5. In the files section under DriverStore locate driver files and copy them to the same folder where you copied DPInst.exe
    Locating driver files in Master Repackager
  6. Locate Trusted Publisher certificates in the registries section
    Locating Trusted Publisher certificate registries in Master Repackager
  7. Open them in RegEdit
    Exporting Trusted Publisher certificate registries from Registry Editor
  8. Export the registries

Add drivers to MSI

  1. Open MSI with Master Packager Master Packager Home screen
  2. In General Information add application name, version, vendor, ect.
  3. Go to the Files section. Create a new folder under [ProgramFilesFolder]\vendors_folder and place the drivers in it Adding files to MST in Master Packager
  4. Drag and drop located files and DPInst.exe exe into the folder and build a Cab file Creating CAB file in Master Packager

Add Trusted Publishers certificates

In Advanced Editor locate Registries section – drag and drop previously exported registries.
Adding registries in Master Packager

Create Custom Actions

Go to Custom Actions.
Adding Custom Actions in Master Packager

Installation Custom Action:

  1. Create a new Custom action called CA_Install_Drivers.
  2. Choose type Exe in File table
  3. As Execution Options select Deferred System
  4. Return Processing – Synchronous, ignore exit code – this will indicate that at installation process it would ignore exit code
  5. Scheduling Options set for Always
  6. Select DPInst.exe file
  7. In command line section add this line: /Q /F /LM /SA
    Creating Custom Action for driver installation in Master Packager

Uninstall Custom Action:

  1. Create a new Custom Action called CA_Uninstall_Driver
  2. Choose type Exe in File table
  3. As Execution Options select Deferred System
  4. Return Processing – Synchronous, ignore exit code
  5. Scheduling Options set for Always
  6. Select DPInst.exe.exe file
  7. In the command line section add this line: /u [#driverkey.inf] /d - replace file key for each driver file that you need to uninstall later. File keys can be found under File table. The file key is the first column of the file table called File.
    Creating Custom Action for driver uninstallation in Master Packager

Pro tip!
To create Uninstall Custom Actions faster for each driver, open Table editor:

  1. Copy CA_Uninstall_Driver row and paste (Ctrl+Shift+C and Ctrl+Shift+C to copy whole row) new Custom actions as many as drivers we have
  2. For each driver that needs uninstall, change the command line’s driver key Custom Action table in Table editor view in Master Packager
  3. To find driver file keys go to File table and click on sequence in descending order to see last added files enter image description here

Add created Custom Actions in InstallExecuteSequence

In advanced editor locate InstallExecuteSequence.
Setting Install Execute Sequence in Master Packager

Add CA_Install_Drivers:

  1. Select Action Type - Custom Actions
  2. Select Action Name – CA_Install_Drivers
  3. Add Condition – During Installation
  4. Set Sequence number – 6500. It must be somewhere between WriteRegistries and InstallFinalize actions
  5. Add Custom Action to the Install Execute Sequence list.
    Setting Install Execute Sequence for Driver installation Custom Action in Master Packager

Add each CA_Uninstall_Driver:

  1. Select Action Type - Custom Actions
  2. Select Action Name – CA_Uninstall_Driver
  3. Add Condition – During Uninstallation
  4. Set Sequence number – 3450. It must be somewhere before RemoveFiles and InstallFinalize actions
  5. Add it to the Install Execute Sequence list
  6. Repeat it to for each uninstall custom action
    Setting Install Execute Sequence for Driver uninstallation Custom Actions in Master Packager

How to Create a Template for Future Use in Master Packager

  1. Open MSI and go to the Custom Actions table
  2. Select CA_Install_Drivers and CA_Uninstall_Driver rows
  3. Right-click on one of the selected rows and press the “Add to Template” button Adding Custom Actions to Template in Master Packager
  4. Create a new template name and press the arrow button in the left textbox Creating new template in Master Packager

Add pre-existing template to your Master Packager

To add a pre-existing template, locate the Master Packager folder in your User Profile’s %appdata% directory.
Add pre-existing template to your Master Packager
You can find your templates in there.

Note! The Template folder will only appear after you create a template in Master Packager.

Summary

Manually installing drivers for each user is time-consuming and inefficient. To install drivers silently, you should use DPInst.exe, Custom Actions and you might need a certificate for some drivers. Using templates in Master Packager allows you to speed up the process of adding custom actions to multiple MSI packages and reduce errors while creating them.

Template for Custom Action to Install Drivers

Subscribe to our newsletters