Friday, July 15, 2011

NSIS - How to Embed Other Installers in Your Installer

Sometimes you may want to embed some other installer in your installer. As an example if you need Java as a prerequisite then you can embed Java installation inside your installer. Then it will run the Java installation before installing your application, when you run your installer. 

So let's write a section to embed JRE installer in your installer
Section "jre" SECJRE
  File "jre-6u14-windows-i586.exe"

  DetailPrint "Starting the JRE installation"   
  ExecWait "$TEMP\jre-6u14-windows-i586.exe" 

In line 2 it is checking the existence of the file "jre-6u14-windows-i586.exe". At the point of compiling NSIS script, this exe should exist in the stated relative path (in this case it should be inside the same folder as the nsis script file). In line 5 it will execute the jre installer and your installation program will be suspended until JRE installation is completed. After the JRE setup is complete it will resume the installation of your application. In this way, you can embed any number of installers inside your installer.

This can be improved in many ways. Well, before installing JRE, you can check whether JRE is already installed in the system. In that case you can consider the version too. If it is not installed then you can use the above script to install JRE. Another improvement is, instead of installing a precise JRE you can download the latest version from Internet and then install. This nsis example shows a similar thing.
Related Posts with Thumbnails