Creating an Installer Using NSIS (I)

Last week I faced a new problem, I had to program a installer for Windows in order to deploy some software we have produced at work. After a quick googling I found NSIS an installer generator, open source and with a simple scripting language.

NSIS comes with a compiler which parses the sentences writting in its own language and produces a pretty decent installer. It also has a look-and-feeling similar to latets Windows versions, so it was the perfect choice!

The scripting language is really simple, we can generate a simple installer with only the next few lines:

outFile “installer.exe”
installDir $DESKTOP
section
userInfo::getAccountType
pop $0
strCmp $0 “Admin” +3
messageBox MB_OK “not admin: $0”
return
messageBox MB_OK “is admin”
setOutPath $INSTDIR
file test.txt
writeUninstaller $INSTDIR\uninstaller.exe
createShortCut “$SMPROGRAMS\new oxtias.lnk” “$INSTDIR\uninstaller.exe”
sectionEnd
section “Uninstall”
delete $INSTDIR\uninstaller.exe
delete $INSTDIR\test.txt
delete “$SMPROGRAMS\new oxtias.lnk”
sectionEnd

OutFile “simpleAdvansenInstaller.exe”

InstallDir $DESKTOP

Section

SetOutPath $INSTDIR

WriteUninstaller $INSTDIR\uninstaller.exe

CreateShortCut “$SMPROGRAMS\simpleAdvansen.lnk” “$INSTDIR\uninstaller.exe”

SectionEnd

Section “Uninstall”

Delete $INSTDIR\uninstaller.exe

Delete $INSTDIR\test.txt

Delete “$SMPROGRAMS\simpleAdvansen.lnk”

SectionEnd

After compiling the script with the tool NSIS package’s comes with, two executables are generated:

simpleAdvansenInstaller.exe

Which will copy the uninstaller.exe to the Installation Dir set up to the Desktop and will add an entry in the Programs Menu for the uninstaller.

uninstaller.exe

Will delete itself and remove the entry in the Programs Menu.

NOTE: NotePad++ highlights the syntax of NSIS as well.