Blog

Using msiexec to manipulate msi files

As I have mentioned in a previous post, the msi file generated by WiX can either be installed by double clicking them and optionally manipulating a UI or it can be run from the command line.

The Windows installer tool msiexec.ese (located in the System32 folder) can be used to install, modify and uninstall msi packages. Today we are going to look at the common ways of using this tool.

Installation

Installation is relatively simple. Simply pass a /i flag along with the msi name:

msiexec /i myApp.msi

This will install the application but will also display the UI if there is one. To suppress the UI use either /QB or /QN. /QB will display a non interactive UI (progress bars etc) while /QN completely suppresses all UI.

Properties can also be supplied at run time. You get this functionality for free with WiX. Its a good idea to provide a list of the properties in a readme file supplied along with the msi file so that admins can easily do network installs. Properties are paired with their values as follows:

msiexec /i myApp.msi  PROPERTY1="propertyValue" PROPERTY2="anotherPropertyValue"

Uninstallation

Uninstallationis just as easy as installation. Simply use:

msiexec /x myApp.msi

Once more this will display a UI which can be suppressed with /QB or /QN. Additionally if the UI is suppressed properties may need to be supplied.

Logging

msiexec offers a logging facility. My personal experience with it has been mixed. In many cases error messages are overly cryptic. To log everything use:

msiexec /i myApp.msi /l myLog.log

In general I have found logging all message to be to verbose, especially for complicated WiX projects that install many components. You can use the following flags to reduce the amount of messages to more manageable levels:

  • i - Status messages
  • w - Nonfatal warnings
  • e - All error messages
  • a - Start up of actions
  • r - Action-specific records
  • u - User requests
  • c - Initial UI parameters
  • m - Out-of-memory or fatal exit information
  • o - Out-of-disk-space messages
  • p - Terminal properties
  • v - Verbose output
  • x - Extra debugging information
      • Append to existing log file
  • ! - Flush each line to the log
      • Log all information, except for v and x options

So you can call:

msiexec /i myApp.msi /le myLog.log

This will log only errors and the final value of all parameters.

Extraction

Occasionally you will download an msi file and want to extract the files but not install them. This can be done easily with the /a flag while setting the TARGETDIR

msiexec /a myApp.msi TARGETDIR="c:\temp"

the files will be extracted to the specified directory. You should not that I have experienced errors on occasion where the TARGETDIR is set to a path that is very long.

To conclude the Windows installer tool is a useful tool for manipulating msi files. As it allows log files to be generated it is a key tool for any WiX developer.