Daniel Watrous on Software Engineering

A Collection of Software Problems and Solutions

Software Engineering

NSIS Installers and ExecWait

This week I’ve been developing an installer using NSIS to facilitate software deployment. Part of the installer requires me to install another application (MySQL in this case) and then run a configuration script against the newly installed software. Here’s the general procedure:

  1. Begin installer (for my software)
  2. Unpack MySQL installer (delivered as an MSI and packed into my installer)
  3. Silently install MySQL. I do this running the installer from the command line like this:
    msiexec /quiet /i mysql.msi
  4. Run the configuration script to install the Windows Service and create an ini file
  5. Continue on with other installer tasks.

Notice that before I move on to step 4 I have to be sure that the installation completes. If installation isn’t complete then the configuration step will fail. I had initially hoped that the ExecWait feature would provide me what I needed, but it didn’t work out that easy.

It turns out that msiexec exits after successfully starting the installer and so step 4 begins before the installation in step 3 completes. A little Google searching brought me to this promising article about using start /wait. However, putting “start /wait” in the command for ExecWait didn’t work.

Solution

Eventually I got the idea that I would add another step. Here’s how it works now:

  1. Begin Installer
  2. Unpack MySQL installer
  3. Build a .bat file with the installer command that I want
    start /wait msiexec /quiet /i mysql.msi
  4. Silently install MySQL by calling the .bat file: ExecWait installmysql.bat
  5. Run the configuration script to install the Windows Service and create an ini file
  6. Continue on with other installer tasks.

Here’s some sample code you can use if you want to accomplish the same thing

  ; Create batch file 
  FileOpen $0 "calcwait.bat" "w"
  FileWrite $0 "start /wait $SYSDIR\calc.exe"
  FileClose $0

  ; View file
  ExecWait '"calcwait.bat"'

2 Comments NSIS Installers and ExecWait

  1. ranulfo

    Thank you for your help!

    mi file .bat only contains the statement “misexec / i ” and it worked perfectly.

    Hugs from a Brazilian friend

    Reply
  2. Whitney

    ; Create batch file
    FileOpen $0 “calcwait.bat” “w”
    FileWrite $0 “start /wait $SYSDIR\calc.exe”
    FileClose $0

    ; View file
    ExecWait ‘”calcwait.bat”‘

    I have used this and it works unless there is a space in the exe path. ex. C:\Users\Test User\calc.exe. Do you know of a solution?

    Reply

Leave A Comment