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:
- Begin installer (for my software)
- Unpack MySQL installer (delivered as an MSI and packed into my installer)
- Silently install MySQL. I do this running the installer from the command line like this:
msiexec /quiet /i mysql.msi
- Run the configuration script to install the Windows Service and create an ini file
- 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:
- Begin Installer
- Unpack MySQL installer
- Build a .bat file with the installer command that I want
start /wait msiexec /quiet /i mysql.msi
- Silently install MySQL by calling the .bat file: ExecWait installmysql.bat
- Run the configuration script to install the Windows Service and create an ini file
- 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"'
Thank you for your help!
mi file .bat only contains the statement “misexec / i ” and it worked perfectly.
Hugs from a Brazilian friend
; 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?