Pages

Thursday, 11 August 2011

Brief NSIS reference

NSIS compiler compiles setup.nsi script into two executables: Installer and Uninstaller. Script contains global statements, and statements within sections and functions. Compiler uses section/function names in order to determine which one belong to Installer and which to Uninstaller.

This is a short (and uncomplete) list of some commands and script features. For detailed reference please look at links at the bottom of the article.

Name app_name - defines the name of the application (product) this installer installs. This name appears in a title bar of the installer's dialog.
Example: Name "My App"

ComponentText text_above text_inst_types text_inst_sect - defines text that appears in the installer dialog. text_above appears above other controls in the dialog, text_inst_types next to installation types select control and text_inst_sect appears next to components sections selection control. This command can be omitted as default text is provided: "Check the components you want to install and uncheck the components you don't want to install. Click Install to start the installation." for text_above and "Select components to install:" for text_inst_sect.

!define symb_name value - defines symbol (its name and value). Like in C/C++ it can be used in conditional compilation and symbol replacement. ${symb_name} refers to the value of the symbol. Symbol is replaced with value both in installer and uninstaller sections. Symbol can contain previously defined symbol - in a form of ${symbol}.

Variable used in Installer and Uninstaller must be set in both sections! Value set in Installer is not available in Uninstaller - variable is uninitialized. It is therefore better to use symbols for const values (e.g. paths or path roots that do not change) that are used both in Installer and Uninstaller.

StrCpy dest_var src_str - copies src_str string to the destination variable dest_var. Can be used ONLY inside Section or Function!
Example:StrCpy $UserName "admin"

Sections appear in section selection control in the order they are listed in the script.
If section_name is omitted, empty string or begins with "-", that section is hidden - it will always be executed!

section_name of Uninstaller section must be "Uninstall" or to begin with "un.".

Option /o makes section unselected by default.

Function func_name - declares beginning of the function... - here are placed function commandsFunctionEnd - declares the end of the function

func_name must start with "un." for function used in Uninstaller. This can be a bit annoying if you want to use the same function both in Installer and Uninstaller sections. With a help of a macro it is possible to map a single piece of code into two functions: Sharing functions between Installer and Uninstaller.

File file_path- copies file from file_path path into current output directory. file_path can be either file's absolute path or path relative to the directory which contains this script.
Example:
File "3rdParty\abc-bin-1.0.0.2.zip"

RMDir [options] dir_path - removes directory/r - recursively delete its contents, directories and files. Without this, directory will be removed only if empty!/REBOOTOK - if directory could not be removed on first attempt, it will be removed after rebootExample:
RMDir ${WEB_DIR}