Improve your contact center performance. See how you can make a difference.
Watch Now
Engage and build your ICT audience with CIOL online advertising.
Know more
The first few instructions of the script define the installer attributes. The attributes that are set here are the window names and the text to be displayed on them. Let's name our application as 'PCQ Application' and its installer as 'PCQAppInstaller.exe.' The following code snippet shows the same:
Name "PCQ Application" Caption "PCQ Demo Application" OutFile "PCQAppInstaller.exe" DirText "Please choose a directory to which you'd like to install PCQ Application." InstallDir "$PROGRAMFILES\PCQ Application"
The 'OutFile' keyword gives the name to the setup program that will be created after compilation and 'InstallDir' creates default location for the installation process. NSIS has some constants like $PROGRAMFILES, $DESKTOP and $SMPROGRAMS which point to the current user's Program Files folder, desktop and Start Menu respectively.
Each script has at least one section. A section carries the instructions for different segments of installation process. Our script has two sections, namely Install and Uninstall. The Install section will have instructions to copy files into installer package, make their shortcuts and registry entries. The code for this is as follows.
Section "install" SetOutPath $INSTDIR\ File E:\nsis_scripts\java_app\PCQ_Test.class ... WriteUninstaller $INSTDIR\Uninstall.exe CreateDirectory "$SMPROGRAMS\PCQ Application" CreateShortCut "$DESKTOP\PCQ Application.lnk" "$SYSDIR\javaw.exe" "PCQ_Test" ... WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PCQ Application" "DisplayName"\ "PCQ Application (remove only)" ... SectionEnd
'SetOutPath' sets the location where the files will be copied upon installation and 'File' keyword packs the files into the installer. The Start Menu program setup for the PCQ Application and the registry entries for the same will be done through 'CreateDirectory' and 'WriteRegStr' respectively. Now if we look at the 'CreateShortCut' instruction, we have three parameters. The first will create the desktop shortcut link for the PCQ Application, second will invoke JRE's javaw.exe to execute the class name passed as third parameter i.e. PCQ_Test. Also, we have to check whether JRE is present on users' machine or not as it is needed to execute our Java program. So, we can add the following snippet to 'install' section to do this check.
readRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" CurrentVersion StrCmp $0 "" NoFound ... NoFound: MessageBox MB_OK "JRE not found. Installation will quit now...
The $0 variable, if blank, shows no JRE is installed otherwise it will store the JRE version. Like other programming languages, conditional checking can be done. 'StrCmp' lets us check for value in $0 variable. If blank, it jumps to NoFound case else it continues with installation. This way the installation setup will be prepared. Finally to make the application uninstallable, we have to create a section 'uninstall.' In this section we give instructions to delete all shortcuts, files and their directories, and also to remove the registry entries. We put the instruction WriteUninstaller $INSTDIR\Uninstall.exe in the install section. Now NSIS will look for an uninstall section in the script while compiling. The snippet for uninstall script is as follows.
<< PREVIOUS NEXT>>