Creating an Installer Using NSIS (III)

In this last post about NSIS I am going to describe how to use some of the most useful plugins which will allow you create a pretty decent and featurefull installer for windows.

  • Checking for adminstrator privileges:

userInfo::getAccountType

Pop $0

StrCmp $0 “Admin” +3
MessageBox MB_OK “Debe tener privilegios de administrador para correr este programa de instalación: $0”
Return

StrCmp $0 “Admin” +3

MessageBox MB_OK “You need Administrator privileges: $0”

Return

This chunk of code will pop up a windows with the propoer notification. The StrCmp sentence compares the $0 variable poped from the stack against “Admin” and if they are equal continue the execution with the 3rd line of code, the one below Return.

  • Downloading and Executing, e.g. an external installer:

NSISdl::download /TIMEOUT=30000 “http://www.advansen.com/this/is/a/test/advansen.msi” “$INSTDIR\advansen.msi”

Pop $R0 ;Get the return value

StrCmp $R0 “success” +3

MessageBox MB_OK “Download failed: $R0”

Quit

ExecWait  ‘”msiexec” /i “$INSTDIR\advansen.msi” /quiet’

  • Unziping :

To use the unzip feature you need to download the unzip external plugin, follow the installation guidelines (basically copying the dll to the plugins directory) and that’s it.

nsisunz::Unzip “$INSTDIR\squid.zip” “C:\”

Pop $R0

StrCmp $R0 “success” +2

DetailPrint “$R0”

Adding to PATH

${EnvVarUpdate} $0 “PATH” “A” “HKLM” “C:\some\path”

Removing a PATH

${un.EnvVarUpdate} $0 “PATH” “R” “HKLM” “C:\some\path”

To use the code above you also need external help, just download the EnvVarUpdate extension and will able to update the $PATH variable easily