\H{variables} Variables

All variables are global and can be used in Sections or Functions. Note that by default, variables are limited to 1024 characters. To extend this limit, \R{build}{build NSIS} with a bigger value of the NSIS_MAX_STRLEN build setting or use the \W{https://nsis.sourceforge.io/download/specialbuilds/}{special build}.

\S1{varuser} User Variables

\e{$VARNAME}

User variables must be declared with the \R{var}{Var} command. You can use these variables to store values, work with string manipulation etc.

\S2{var} Var

\c [/GLOBAL] var_name

Declare a user variable. Allowed characters for variables names: [a-z][A-Z][0-9], '.' and '_'. All defined variables are global, even if defined in a section or a function. To make this clear, variables defined in a section or a function must use the /GLOBAL flag. The /GLOBAL flag is not required outside of sections and functions.

\c Var example
\c
\c Function testVar
\c   Var /GLOBAL example2
\c 
\c   StrCpy $example "example value"
\c   StrCpy $example2 "another example value"
\c FunctionEnd

\S1{varother} Other Writable Variables

\e{$0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $R0, $R1, $R2, $R3, $R4, $R5, $R6, $R7, $R8, $R9}

Registers. These variables can be used just like user variables, but are usually used in shared functions or macros. You don't have to declare these variables so you won't get any name conflicts when using them in shared code. When using these variables in shared code it's recommended that you use the stack to save and restore their original values. These variables can also be used for communication with plug-ins because they can be read and written by the plug-in DLLs.

\e{$INSTDIR}

The installation directory ($INSTDIR is modifiable using \R{StrCpy}{StrCpy}, \R{readregstr}{ReadRegStr}, \R{readinistr}{ReadINIStr}, etc. - This could be used, for example, in the \R{oninit}{.onInit} function to do a more advanced detection of install location).

Note that in uninstaller code, $INSTDIR contains the directory where the uninstaller lies. It does \s{not} necessarily contain the same value it contained in the installer. For example, if you write the uninstaller to $WINDIR and the user doesn't move it, $INSTDIR will be $WINDIR in the uninstaller. If you write the uninstaller to another location, you should keep the installer's $INSTDIR in the registry or an alternative storing facility and read it in the uninstaller.

\e{$OUTDIR}

The current output directory (set implicitly via \R{setoutpath}{SetOutPath} or explicitly via \R{StrCpy}{StrCpy}, \R{readregstr}{ReadRegStr}, \R{readinistr}{ReadINIStr}, etc)

\e{$CMDLINE}

The command line of the installer. The format of the command line can be one of the following:

\b "full\\path to\\installer.exe" PARAMETER PARAMETER PARAMETER

\b installer.exe PARAMETER PARAMETER PARAMETER

\b For parsing out the PARAMETER portion, see \R{getparameters}{GetParameters}. If /D= is specified on the command line (to override the install directory) it won't show up in $CMDLINE.

\e{$LANGUAGE}

The identifier of the language that is currently used. For example, English is 1033. You can only change this variable in \R{oninit}{.onInit}.

\S1{varconstant} Constants

Constants can also be used in the \R{ainstalldir}{InstallDir} attribute.

Note that some of the new constants will not work on every OS. For example, $CDBURN_AREA will only work on Windows XP and above. If it's used on Windows 98, it'll be empty. Unless mentioned otherwise, a constant should be available on every OS.

\e{$PROGRAMFILES}, \e{$PROGRAMFILES32}, \e{$PROGRAMFILES64}

The program files directory (usually \c{C:\\Program Files} but detected at runtime). On 64-bit Windows, $PROGRAMFILES and $PROGRAMFILES32 point to \c{C:\\Program Files (x86)} while $PROGRAMFILES64 points to \c{C:\\Program Files}. Use $PROGRAMFILES64 when installing 64-bit applications.

\e{$COMMONFILES}, \e{$COMMONFILES32}, \e{$COMMONFILES64}

The common files directory. This is a directory for components that are shared across applications (usually \c{C:\\Program Files\\Common Files} but detected at runtime). On 64-bit Windows, $COMMONFILES and $COMMONFILES32 point to \c{C:\\Program Files (x86)\\Common Files} while $COMMONFILES64 points to \c{C:\\Program Files\\Common Files}. Use $COMMONFILES64 when installing 64-bit applications.

\e{$DESKTOP}

The Windows desktop directory. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

\e{$EXEDIR}

The directory containing the installer executable (technically this is a variable and you can modify it, but it is probably not a good idea).

\e{$EXEFILE}

The base name of the installer executable.

\e{$EXEPATH}

The full path of the installer executable.

\e{$\{NSISDIR\}}

A symbol that contains the path where NSIS is installed. Useful if you want to reference resources that are in NSIS directory e.g. Icons, UIs etc.

When compiled with support for keeping makensis and the data in the same place (the default on Windows), it is in the same place as makensis, on other platforms it is set at compile time (See the INSTALL file for info). In both instances you can modify it at runtime by setting the NSISDIR environment variable. See \k{usageenvironment} for more info.

\e{$WINDIR}

The Windows directory (usually \c{C:\\Windows} or \c{C:\\WinNT} but detected at runtime).

\e{$SYSDIR}

The Windows system directory (usually \c{C:\\Windows\\System} or \c{C:\\WinNT\\System32} but detected at runtime).

\e{$TEMP}

The temporary directory.

\e{$STARTMENU}

The start menu folder (useful for adding start menu items using \R{createshortcut}{CreateShortcut}). The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

\e{$SMPROGRAMS}

The start menu programs folder (use this whenever you want $STARTMENU\\Programs). The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

\e{$SMSTARTUP}

The start menu programs / startup folder. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

\e{$QUICKLAUNCH}

The quick launch folder for IE4 active desktop and above. If quick launch is not available it simply returns the same as $TEMP.

\e{$DOCUMENTS}

The documents directory. A typical path for the current user is \c{C:\\Users\\Foo\\My Documents}. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

This constant is not available on Windows 95 unless Internet Explorer 4 is installed.

\e{$SENDTO}

The directory that contains Send To menu shortcut items.

\e{$RECENT}

The directory that contains shortcuts to the user's recently used documents.

\e{$FAVORITES}

The directory that contains shortcuts to the user's favorite websites, documents, etc. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

This constant is not available on Windows 95 unless Internet Explorer 4 is installed.

\e{$MUSIC}

The user's music files directory. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

This constant is available on Windows ME, XP and above.

\e{$PICTURES}

The user's picture files directory. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

This constant is available on Windows 2000, XP, ME and above.

\e{$VIDEOS}

The user's video files directory. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

This constant is available on Windows ME, XP and above.

\e{$NETHOOD}

The directory that contains link objects that may exist in the My Network Places/Network Neighborhood folder.

This constant is not available on Windows 95 unless Internet Explorer 4 with Active Desktop is installed.

\e{$FONTS}

The system's fonts directory.

\e{$TEMPLATES}

The document templates directory. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

\e{$APPDATA}

The (roaming) application data directory.\#{ Detection of the current user path requires Internet Explorer 4 and above. Detection of the all users path requires Internet Explorer 5 and above. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.}

This constant is not available on Windows 95 unless Internet Explorer 4 with Active Desktop is installed.

\e{$LOCALAPPDATA}

The local (non-roaming) application data directory. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user. The All Users location is also known as \cw{%ProgramData%} on Vista and above.

This constant is available on Windows ME, 2000 and above.

\e{$PRINTHOOD}

The directory that contains link objects that may exist in the Printers folder.

This constant is not available on Windows 95 and Windows 98.

\e{$INTERNET_CACHE}

Internet Explorer's temporary internet files directory.

This constant is not available on Windows 95 nor Windows NT 4 unless Internet Explorer 4 with Active Desktop is installed.

\e{$COOKIES}

Internet Explorer's cookies directory.

This constant is not available on Windows 95 nor Windows NT 4 unless Internet Explorer 4 with Active Desktop is installed.

\e{$HISTORY}

Internet Explorer's history directory.

This constant is not available on Windows 95 nor Windows NT 4 unless Internet Explorer 4 with Active Desktop is installed.

\e{$PROFILE}

The user's profile directory. A typical path is \c{C:\\Users\\Foo}.

This constant is available on Windows 2000 and above.

\e{$ADMINTOOLS}

A directory where administrative tools are kept. The context of this constant (All Users or Current user) depends on the \R{setshellvarcontext}{SetShellVarContext} setting. The default is the current user.

This constant is available on Windows 2000, ME and above.

\e{$RESOURCES}

The resources directory that stores themes and other Windows resources (usually \c{$WINDIR\\Resources} but detected at runtime).

This constant is available on Windows XP and above.

\e{$RESOURCES_LOCALIZED}

The localized resources directory that stores themes and other Windows resources (usually \c{$WINDIR\\Resources\\1033} but detected at runtime).

This constant is available on Windows XP and above.

\e{$CDBURN_AREA}

A directory where files awaiting to be burned to CD are stored.

This constant is available on Windows XP and above.

\e{$HWNDPARENT}

HWND of the main window (in decimal).

\e{$PLUGINSDIR}

The path to a temporary folder created upon the first usage of a plug-in or a call to \R{initpluginsdir}{InitPluginsDir}. This folder is automatically deleted when the installer exits. This makes this folder the ideal folder to hold INI files for \L{../Docs/InstallOptions/Readme.html}{InstallOptions}, bitmaps for the splash plug-in, or any other file that a plug-in needs to work.

\e{$USER..} and \e{$COMMON..}

A handful of constants are available as aliases that are not affected by \R{setshellvarcontext}{SetShellVarContext}: \e{$USERTEMPLATES}, \e{$USERSTARTMENU}, \e{$USERSMPROGRAMS}, \e{$USERDESKTOP}, \e{$COMMONTEMPLATES}, \e{$COMMONSTARTMENU}, \e{$COMMONSMPROGRAMS}, \e{$COMMONDESKTOP} and \e{$COMMONPROGRAMDATA}.

\S1{varstrings} Constants Used in Strings

\e{$$}

Use to represent $.

\e{$\\r}

Use to represent a carriage return (\\r).

\e{$\\n}

Use to represent a newline (\\n).

\e{$\\t}

Use to represent a tab (\\t).
