Advertisements
TRENDING

Silently Installing Applications with MSI – Part 1: Switches

Command-Line Options

For most of general public, installing an application, either from an EXE or an MSI is a pretty straightforward process. Double-click said EXE or MSI, keep pressing Next until you get a Finish or Close button and you're done. Occasionally, you may change some of the attributes, like installing it in a different location, or turning on/off certain features. All simple enough.

But, what if you want to install that same application on hundreds or thousands of computers? What if you want to set up a process that quickly installs your favorite applications on a new computer, or after reinstalling an OS, automatically with all your favorite settings and zero-touch. Or, in the case of what first brought me to BJ’s Tech news, installing applications automatically as part of a deployment process. That’s where the automation features of MSI installers come in handy. In the case of Windows installers, EXE’s and MSI’s are pretty much it for installing applications. I may come back and do a follow up on this for installing EXE based applications, but, for the moment, I’m going to focus specifically on MSI based installers.

MSI installers are, generally, composed of a database and a list of files, the actual files that will be installed on your computer. Sometimes these files are placed in an external CAB file that the MSI is linked to. The database tells the MSI Executor where to place those files. It also allows you a huge amount of control over the MSI and how it’s set up on your computer.

Getting Started:

The first step is to get your hands on the MSI. A number of applications come in MSI format, so you can just download those directly, like the MDT installers. Sometimes, the MSI files are compacted in to an EXE file. In order to get the MSI from the EXE, you can use programs like 7-zip or WinZip, right click on the EXE and chose to extract the files (permitted you have allowed your zip program access to the Windows Shell). Once you have the files extracted you can find the MSI. In some circumstances, this is a little trickier and the EXE doesn’t let you extract the files. In this instance, you can often find the MSI by running the EXE, waiting for it’s initial loading stage, which usually will show you a dialog box saying it’s extracting files, and then looking for the MSI in your Temp folder, either in “C:\Windows\Temp”, or, more likely, in the Temp folder in your personal AppData folder (“C:\Users\%USERNAME%\AppData\Local\Temp”). Another option is to do a search for the Offline Installer for the program you are looking for. If you still can’t get an MSI file at this point, it may not be possible, or you’d have to get a little trickier with the extraction process, which is beyond the scope of this blog. You can also use tools to repackage an EXE, or even another MSI, in to an MSI, but I don’t recommend those except in an absolute last-ditch-effort because they are usually not very good at capturing a whole install, or they capture too much. You really have to know what you are doing and have a very in-depth knowledge of the program and the OS to make them work properly. For my part, I only use these tools to see what an installer is doing, where it’s placing the files, what registry settings it’s accessing, what values it’s putting in INI.

Now that you have your hands on your MSI, we can get started on silently automation the install. There are two ways in which this is accomplished: switches, and properties. To get the most out of an silent install, you’ll probably use both. If it’s a very straightforward install you’ll probably only need the switches. So, I’ll start with those first and follow up with Options in the next post.

MSI Switches:

Getting the list of switches for MSI installs is pretty simple. Open a Command Prompt, type “msiexec /?” and you’ll get a list of switches, which can also be found here. So, all command lines for MSI’s start with “msiexec.exe” (the “.exe” is not really necessary). There are four basic switches for how you want to handle the MSI: /i, /x and /f.

  • /i = Install the MSI product
  • /x = Uninstall the MSI product
  • /f = Repair the MSI product. You’ll see from the link above that there are a number of options for this switch, allowing you to control what gets repaired.
  • /a = Creates an administrative install for the MSI that can be placed on a network share and installed from there. This option allows you add patches or updates to the admin install to keep it up to date.

For the purposes of this article, we’re going to stick with /i for now. So, say I want to install the current version of 7-Zip on my computer silently. I know that I need the /i switch and I have the 7-Zip msi located in D:\Downloads\7z920-x64.msi. The basic command to run this install is:

msiexec /i “D:\Downloads\7z920-x64.msi”

Note that the quotation marks around the file name are only necessary is you have a space in the path or file name, but it doesn’t hurt anything to use them all the time. This command line will install the 7-zip program, however, I could have accomplished the same thing by double-clicking the MSI. I want this to install silently, so the MSI Installer gives me a number of switch options for this:

  • /quiet
  • /passive
  • /q {n|b|r|f}

The /quiet and /passive options are older options but still work with a number of new MSI’s. The newer MSI Installer, though, has a preference for the /q switch. In practice, I’ve found that there are circumstances where /passive works where /q doesn’t and vice-versa. It’s best to try a test install with the /q option first and, if that doesn’t work, use the /passive. You’ll also notice that the /q has options of it’s own: n,b,r,f. These options allow you to control the level of the UI that the user sees.

/qf is a full UI, the same as you would see if you double-clicked on the file, which isn’t overly helpful if you want a silent install.
/qr gives you a slightly reduced UI, meaning some parts or options will be automatically selected, but you would still be asked some questions. Still not useful for silent installs.
/qn is a completely silent install where nothing is shown on the screen at all and everything is installed in the background. This also gives you another option with /qn+ which will install silently, but still give you a modal dialog box at the end to let you know it’s done. /q an /qn achieve the same result
/qb is a basic UI. This is my personal preference because it doesn’t prompt for any user input, but gives you a progress bar so that you can see the install in progress. This way, you know it’s running. /qb also gives you another list of options

  • /qb!   This option disables the cancel button so that the install can’t be stopped.
  • /qb+  This option suppresses the UI and only shows the progress bar, but also gives you a modal dialog box at the end. The cancel button can also be removed with /qb!+ or /qb+!
  • /qb-   This option suppresses the UI and only shows the progress bar with no modal dialog box at the end. This is the same as /qb. The cancel button can also be removed with /qb!- or /qb-!

So, say we want a silent install, default options, progress bar and the user can’t cancel, the command line becomes:

msiexec /i “D:\Downloads\7z920-x64.msi” /qb!

That’s it! You now have a command line for a silent install of 7-zip or, for that matter, any MSI you want to install.

There are other options as well that can be added if you want to, such as:

  • /L which turns on logging options. There are a number of options for this switch that give varying amounts of data in the log file. Just append “/L{options} LogFilePath\LogFileFileName” to your command line. Remember to use quotation marks around the LogFilePath\LogFileFileName option if you have spaces
  • /p applies patches to the MSI. Just append “/p PatchPath\PatchFileName” to the end. If you have more than one patch, type them in order separated by a semi-colon, ex: “/p PatchPath1\Patch1;PatchPath2\Patch2”

It doesn’t matter which way you order the switches on the command line, the MSI installer will still interpret them, just remember that the switch and it’s options have to go together. ‘msiexec /i /qb! “D:\Downloads\7z920-x64.msi” ‘ is invalid because the /i option of “D:\Downloads\7z920-x64.msi” is not right after the switch.

In the next article, I’ll run down the MSI Public Properties and how you can find them.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s