The main purpose of Inno Setup Preprocessor (ISPP) is to automate compile-time tasks and avoid repetition in your scripts. For example, you can declare a compile-time preprocessor variable ‐ containing your application name, for instance ‐ and then use its value in several places of your script. If for some reason you need to change the name of your application, you'll have to change it only once in your script. Without the preprocessor, you would need to change all occurrences of your application name throughout the script.
Another example of using the preprocessor would be gathering version information from your application at compile-time by reading the version info of an EXE file, and using it in your AppVerName [Setup] section directive or anywhere else. Without the preprocessor, you would have to modify your script each time the version of your application changes.
The preprocessor can even scan your source folder and generate script lines for the found files. Without the preprocessor, you would have to manually maintain the list of files.
Conditional in- and exclusion of portions of script is also possible by using the preprocessor: you can create one single script for different versions/levels of your applications (for example, trial versus fully functional). Without the preprocessor, you would need multiple scripts.
Finally, the preprocessor makes it possible to split long lines using a line spanning symbol.
Note: the preprocessor works exclusively at compile-time, and has no run-time functionality.
All topicsDirectives Reference
There are two kinds of directives in ISPP: simple and inline.
Simple directives occupy a whole line and begin with the # symbol. For example the following defines a variable called MyAppName:
#define MyAppName "My Program"
Inline directives appear inside other lines and begin with {# and end with }. For example the following sets Inno Setup's AppName directive to the value of the previously defined variable:
[Setup]AppName={#MyAppName}
As seen in the above example it is not necessary to specify the name of the &emit; directive when it is used inline, so {#MyAppName} is short for {#emit MyAppName}.
Directive usage syntax uses the following conventions.
()
Group of tokens.
[]
Optional token or group of tokens.
|
Mutually exclusive tokens.
...
Previous token or group of tokens can be repeated.
token
Reserved word or symbol(s). Must be typed exactly as shown.
<token>
Non-terminal. Its syntax is either shown before, or explained.
Available directives#define#:defineident=exprident()exprdefine:,ident=expr*identanyintstrfuncprivateprotectedpublic
The first syntax ("variable-definition") defines a variable named ident, or assigns a value to an element of an array named ident (use &dim; instead of define to define the array variable itself). If none of the public, protected, or private keywords are specified, default visibility is assumed.
The second syntax ("macro-definition") defines a user defined function named ident. When defining a user defined function there must be no whitespace between the name and opening parenthesis, otherwise it will be treated as variable declaration.
The third syntax ("default-visibility-set") sets the default visibility of further variable and user defined function definitions in this file. If no visibility declaration occurs in a file, public visibility is assumed by default.
#define MyAppName "My Program"#define MyAppExe MyAppName + ".exe"#define MyAppVer GetVersionNumbersString(MyAppExe)#define MyArray[0] 15#define Multiply(int A, int B = 10) A * B
Use &dim; to define an array variable, set its dimension and optionally intialize it. All unitialized elements of the array are initialized to null (void). To assign an element value after declaring the array, use &define;. Instead of assigning element values with &define;, it is also possible to set an element value by using it as the left operand of an assignment.
Use &redim; to increase or decrease the dimension of an existing array variable. All new elements of the array are initialized to null (void) and existing elements are left unchanged. Identical to &dim; if ident isn't an existing array variable.
Undefines (removes) a variable or user defined function. If no visibility (public, protected, or private) is specified, ISPP first tries to remove a private variable of the given name, then protected, then public.
#undef MyVar#undef MyFunction#undef public MyVar
&define;, &dim;, .
#include#+include<filename>exprinclude+
Includes the &translation; of the specified file. If an Unicode file is used, it must be UTF-8 (with or without a BOM) encoded
If the filename is enclosed in quotes, ISPP first searches for the file in the directory where current file resides, then in the directory where the file that included current file resides, and so on. If the file is not found, it is searched on current include path, set via &pragma;, then on the path specified by INCLUDE environment variable.
If filename is an expression or specified in angle brackets, it is searched on current include path only.
The filename may be prefixed by "compiler:", in which case it looks for the file in the Compiler directory.
Replaces the directive with the name of a temporary file containing the &translation; of the specified file. Upon end of compilation, the temporary file is automatically deleted. If an Unicode file is used, it must be UTF-8 (with or without a BOM) encoded.
Including a file using this directive creates a new independent instance of the preprocessor, passing it options currently in effect and all declared identifiers. If the included file modifies options in some way, they are not propagated back.
When using this directive in Inno Setup's Source parameter of the [Files] section, specify a DestName parameter too, else the file with not be installed with the original name.
This directive can only be used inline.
[Setup]LicenseFile={#file "mylic.txt"}
&include;.
#emit#=emitexpremit=
Replaces the directive with the value of &expr;.
When used inline, the name of this directive can be omitted unless &expr; begins with the name of another directive.
This means you can, for example, use {#MyDestDir} instead of {#emit MyDestDir} or {#=MyDestDir}
[Setup]AppVersion={#GetVersionNumbersString(AddBackslash(SourcePath) + "MyProg.exe")}[Files]#emit 'Source: "file1.ext"; DestDir: ' + MyDestDirSource: "file2.ext"; DestDir: {#MyDestDir}#emit GenerateVisualCppFilesEntries ; user defined function[Code]const&dsp;AppName = '{#SetupSetting("AppName")}';
expr.
#expr#!exprexprexpr!
Evaluates an expression ignoring its result. This directive acts like &emit; with the exception that it doesn't emit anything to the &translation;.
This directive is intended to be used with functions that produce side effects and do not return any significant value.
Changes the insertion point. By default, each processed line is appended to the end of the &translation;. Using &insert; the point at which the next processed line will be inserted into the &translation; can be set. &insert; takes an expression which must evaluate to a 0-based line index. If this index is 0, the next processed line is inserted at the beginning of the &translation;. If this index is 1, the next processed line is put in the second position of the &translation;, and so on.
The insertion point is also always automatically incremented each time after a line has been added to the &translation;, so that each new line is inserted after the one previously inserted.
It is not recommended to use script generating functions (such as SetSetupSetting) which may insert a line by themselves, thus shifting a part of the &translation; one line down, whereas insertion point is not updated. This may result in different insertion point than expected.
The Find function can be used to produce values for the &insert; directive.
The &if;, &elif;, &else;, and &endif; conditional directives control in- and exclusion of portions of script.
ISPP first evaluates the expressions following each &if; or &elif; directive until it finds one evaluating to non-zero. It then selects the portion of script following this directive up to its associated &elif;, &else;, or &endif;. Earlier portions which followed an &if; or &elif; which evaluated to zero, or which follows any next &elif; are not selected and thus not seen by the Inno Setup compiler.
If no expression evaluated to non-zero, the preprocessor selects the script portion after the &else; directive if present, otherwise nothing is selected.
Finally, after selecting any script portion, ISPP preprocesses it too, so if it contains other preprocessor directives, ISPP carries out those directives as well.
Each &if; directive in a source file must be matched by a closing &endif; directive. Any number of &elif; directives can appear between the &if; and &endif; directives, but at most one &else; directive is allowed. The &else; directive, if present, must be the last directive before &endif;.
The &if;, &elif;, &else;, and &endif; directives can be nested. Each nested &else;, &elif;, or &endif; directive belongs to the closest preceding &if; directive.
Inline conditional directives may not be mixed with simple. If the &if; directive is simple (occupying a whole line), its associated directives (&elif;, &else;, or &endif;) must also be simple and not inline (appearing inside other lines).
You can use the &ifdef;, &ifndef;, &ifexist;, and &ifnexist; directives anywhere &if; can be used. The ifdef identifier statement is equivalent to if 1 when the specified identifier has been defined, and equivalent to if 0 when the identifier has not been defined or has been undefined with the &undef; directive. These directives check only for the presence or absence of identifiers defined with &define;.
&ifexist; and &ifnexist; directives check for presence and absence of the file, respectively.
Use the &for; directive to get loop behaviour. &for; takes 4 expressions. The first expression (expr1) is called "initialization expression", the second expression (expr2) "condition", the third expression (expr3) "action", and the final expression (expr4) "loop body".
The logic the &for; directive follows is:
&dsp;1. The initialization expression is evaluated.
&dsp;2. The condition is evaluated. If it evaluates to 0, the loop ends.
&dsp;3. The loop body is evaluated.
&dsp;4. The action is evaluated.
&dsp;5. Process repeats from 2.
// Call AddFile user defined procedure 200 times#for {i = 200; i > 0; i--} AddFile
, .
⊂, &include;.
#sub, #endsubsub#endsubendsubsubidentendsub
⊂ and &endsub; directives are used to declare a user defined procedure which is a portion of script which may be included later once or several times. You may think of a user defined procedure as being similar to an external file, and a call to a user defined procedure as being similar to inclusion of an external file, except that procedures may also be called from within expressions. Please note that it is strongly not recommended to call procedures which emit several lines to the &translation; from within compound expressions or directives.
A procedure is called by simply specifying its identifier, with which it was declared.
A procedure is not processed in any way until it is called, so if any errors exist in its body, they will only pop up when the procedure is called.
&pragma; is a special directive. Please note that if ISPP fails to parse parameters of this directive (because of typo or wrong syntax), no error will occur ‐ only a warning will be issued; this is done for compatibility with other preprocessors, which can have their own syntax of &pragma; directive.
The "pragma-option" variant of &pragma; directive controls the options which ISPP uses to read the source. Each option has an assigned letter and you specify options by typing group name (option or parseroption),
then the letter prefixed by a dash. After the letter a plus must be used to turn the option on and minus turn it off. Multiple options can be specified at once (see syntax).
The first group of options (option) controls the general options, while the second group (parseroption) controls options specific to parser. The list of options is provided at the end of this topic.
The "pragma-itokens" variant is used to specify inline directive terminators: starting and ending, respectively. After the token description keyword (inlinestart or inlineend) a string type expression must follow. It must not evaluate to an empty string. It is allowed to specify the same token for both starting and ending terminators. By default, {# (opening brace and a pound sign) and } (closing brace) are assumed.
The "pramga-msg" variant issues a message of the type specified by the keyword following the directive name. Messages and warnings are sent to the messages window of the compiler. Errors are shown (by the compiler) using message boxes. Expression must be of type string. Also see the &error; directive.
The "pragma-verblev" variant turns on verbose mode and sets the level of verbosity which controls the importance of messages (see below). Least important messages will show up only when highest verbose level is set.
The "pragma-include" variant sets the include path. Expression may specify multiple paths delimited with semicolons. The list of these directories is used when ISPP tries to find a file, mentioned in &include; directive.
The "prama-spansymb" variant sets the symbol used to span multiple lines together. Expression must not evaluate to an empty string. Only first symbol in string is taken.
c
Indicates that the &translation; should be sent to the compiler after preprocessing is done. Default state: on.
e
Specifies whether empty lines or lines with only whitespace should be emitted to the &translation;. Default state: on.
v
Turns on/off the verbose mode. Default state: off.
b
Short-circuit boolean evaluation. Default state: on.
m
Short-circuit multiplication evaluation. (In "0 * A", A will not be evaluated, since the result of expression is known to be zero.) Default state: off.
p
Pascal-style string literals. In off state, uses C-style string literals (with escape sequences). Default state: on.
u
Allow undeclared identifiers. If an undefined identifier is encountered, ISPP will raise an error unless this option is turned on, in which case a standalone identifier (the one that does not look like a function call) will be considered void value. Default state: off.
0
Verbosity level messages
1
Messages about any temporary files created by #file
2
#insert and #append messages
4
#dim, #define and #undef messages
6
Conditional inclusion messages
8
#emit messages
9
Macro and functions call messages
10
Local macro array allocation messages
#pragma parseroption -b- -u+#pragma option -c-#pragma warning "Variable value is: " + Str(MyVar)#pragma option -v+#pragma verboselevel 9#pragma inlinestart "$("#pragma inlineend ")"#pragma include __INCLUDE__ + ";D:\INCLUDE"#pragma spansymbol "_"
Message, Warning, Error.
#errorerrorerrortext
Causes the Inno Setup compiler to issue an error message with the specified text. Unlike pragma error, text in error directive is not parsed, so it is recommended to use this directive instead of &pragma; when possible to avoid possible syntax errors that may hide real errors your script is trying to report.
#if VER < EncodeVer(5,4,2)&dsp;#error A more recent version of Inno Setup is required to compile this script (5.4.2 or newer)#endif
&pragma;, &if;, Error.
Support Functions Reference
There are a number of built-in support functions which you can use to perform compile-time actions and/or change your script. For example the following uses ISPP function GetVersionNumbersString to read version info from an EXE and uses the return value of the function to set the AppVerName [Setup] section directive using directive &emit;:
#define MyAppVer GetVersionNumbersString(AddBackslash(SourcePath) + "MyProg.exe")[Setup]AppVerName=MyProg version {#MyAppVer}
Built-in support functions can also be called directly from directive &emit;. For example:
Function prototypes show the function result type, name, and parameters.
Return and parameter types int, str, any, and void respectively specify the integer type, the string type, any type, and the null type. The integer type is a signed 64-bit integer. When the null type is specified as a function result type then the function does not return a value.
A question mark (?) after an parameter type means that the parameter is optional.
Available functionsGetStringFileInfo
str GetStringFileInfo(str 1, str 2, int? 3)
Retrieves string from specified file's (first parameter) version information resource.
Second parameter is the name of the version info string-value. This should be one of the predefined strings. Those strings and shortcuts are declared in &builtins;.
Third optional parameter should specify the language and charset identifier. For example: 0x04BE0409 stands for "English (United States)". If this parameter is omitted, ISPP scans for all available version info blocks to find the value.
The function returns an empty string, if it was unable to retrieve the desired string-value.
Int
int Int(any 1, int? 2)
Converts an expression (first parameter) to its integer representation. If the expression is an integer, the result of the function is the expression value. If the expression is void, the result is 0. If the expression is string, ISPP tries to convert it to integer; if such attempt fails, an error is raised unless second parameter specifies the default result.
Str
str Str(any)
Converts an expression to string. If the expression is integer, the result is its string representation. If the expression is void, the result is an empty string. Otherwise the result is the value of the expression.
FileExists
int FileExists(str)
Returns non-zero value if the specified file exists.
DirExists
int DirExists(str)
Returns non-zero value if the specified directory exists.
ForceDirectories
int ForceDirectories(str)
Creates all the directories along the specified directory path all at once. If the first directories in the path do exist, but the latter ones don't, ForceDirectories creates just the ones that don't exist. Returns non-zero value if successful.
FileSize
int FileSize(str)
Returns size, in bytes, of the specified file. If the file does not exist, the result is -1.
ReadIni
str ReadIni(str 1, str 2, str 3, str? 4)
Reads the value from an INI file. Parameter 1 must be the name of the INI file, parameter 2 ‐ the name of a section in the INI file, the third parameter is the key in the section to read. Last optional parameter can be used to provide the default value that will be returned on failure, if it is omitted, an empty string is returned.
WriteIni
void WriteIni(str 1, str 2, str 3, any 4)
Writes specified value to an INI file. Parameter 1 is the name of the INI file, parameter 2 ‐ the name of a section in the INI file, parameter 3 ‐ the name of a key in the section. Last parameter should be set to the value you wish to be written to the INI file, it can be of any type.
ReadReg
any ReadReg(int RootKey, str SubKey, str? Name, any? Default)
Reads the value of the specified registry key. First parameter is the root key, such as HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE_32 or HKEY_LOCAL_MACHINE_64. Constants for use with this parameter are declared in &builtins; accompanying ISPP. Second parameter specifies a subkey. Third parameter specifies the name of the value, if this parameter is omitted, a default value is assumed. Last optional parameter may be used to specify the default value that will be returned on failure.
Note that this function can return a value of any type depending on the type of actual value in the registry.
The Filename parameter specifies the filename of the executable or batch file. If this does not includes quotes then the function will add them automatically. If you have a single string containing both a filename and parameters (e.g. a command line obtained from an UninstallString registry value), you need not separate them yourself; just pass '>' in this parameter, and the full command line in the Params parameter. (Note that when this is done, the function's special platform-independent support for .bat and .cmd files is disabled; it simply passes the specified command line to CreateProcess without any processing.)
The Params parameter may be used to specify parameters for the process.
The WorkingDir parameter may be used to specify the working directory of the process. If this is omitted or empty it will try to extract a pathname from the Filename parameter and use that as the initial current directory for the process.
The Wait parameter may be set to zero if you don't wish to wait for the process to finish, and non-zero otherwise. By default, non-zero value is assumed.
The ShowCmd parameter may be any of the SW_* constants defined in &builtins;. Console programs are always hidden and the ShowCmd parameter only affects GUI programs, so always using SW_SHOWNORMAL (the default) instead of SW_HIDE is recommended.
If the Wait parameter is omitted or is non-zero, the function returns the exit code of the process. Otherwise, the function result indicates whether the process has been successfully launched (non-zero for success).
Note: compared to Pascal Scripting's Exec the Wait and ShowCmd parameters are swapped!
Executes specified executable or batch file and reads the first non-empty line from its output.
The Filename parameter specifies the filename of the executable or batch file. If this does not includes quotes then the function will add them automatically. If you have a single string containing both a filename and parameters (e.g. a command line obtained from an UninstallString registry value), you need not separate them yourself; just pass '>' in this parameter, and the full command line in the Params parameter. (Note that when this is done, the function's special platform-independent support for .bat and .cmd files is disabled; it simply passes the specified command line to CreateProcess without any processing.)
The Params parameter may be used to specify parameters for the process.
The WorkingDir parameter may be used to specify the working directory of the process. If this is omitted or empty it will try to extract a pathname from the Filename parameter and use that as the initial current directory for the process.
Exec
Copy
str Copy(str 1, int 2, int? 3)
Extracts a substring from a string (first parameter). The 1-based index of the character from which the substring should start is specified by the second parameter. The third parameter specifies the number of characters to take, if it is omitted, all characters up to the end of the string are copied to the result.
Pos
int Pos(str SubStr, str S)
Searches for SubStr within S and returns the first index of SubStr within S, 1-based. If SubStr is not found, Pos returns zero. The Pos function is case-sensitive.
RPos
int RPos(str SubStr, str S)
Searches for SubStr within S and returns the last index of SubStr within S, 1-based. If SubStr is not found, RPos returns zero. The RPos function is case-sensitive.
Intended to be used with &insert; directive: returns the 0-based index of the first line in the &translation; matching the specified criteria. Return less than 0 if not match was found.
First parameter denotes the 0-based index of the line to start the search from, usually it is set to zero.
Second, fourth, and sixth parameters should specify string(s) to search within each line. Only the first string must be specified, whereas the others may be omitted.
Third, fifth, and seventh parameters should specify the search flags for each string meaning that first flags parameter specifies flags for the first string, and so on.
See Find flags topic for the description of the available search flags.
If any of the 'flags' parameters is omitted but the string parameter preceding it is specified, FIND_MATCH | FIND_AND (i. e. 0) is used.
&insert;.
Find flags
One of the following four values must be specified:
FIND_MATCH (0) means that the line must match the search string.
FIND_BEGINS (1) means that the line must start with the search string.
FIND_ENDS (2) means that the line must end with the search string.
FIND_CONTAINS (3) means that the line must contain (i. e. it also can match, begin, or end with) the search string.
Any of the following modifiers may be combined with one of the previous using bitwise OR operator (|):
FIND_CASESENSITIVE (4) means that comparison must be case-sensitive.
FIND_AND (0) means that this criterium (the pair of parameters in Find function) must be met as well as previous criteria. Has no effect for the first criterium.
FIND_OR (8) means that it is allowed that this criterium is tested even if previous criteria were not met. Has no effect for the first criterium.
FIND_NOT (16) means that this criterium must not be met.
FIND_AND and FIND_OR are mutually exclusive. If both are specified, FIND_OR takes precedence.
Special flags:
FIND_TRIM (32) means that leading and trailing whitespaces must be stripped off from the line prior to testing it against all the criteria. This flag can only be used for the first criterium, and has no effect if used for the others. It is not mutually exclusive with any of the previously mentioned flags.
SetupSetting
str SetupSetting(str)
Parses [Setup] section in &curtrans; to find the key whose name is specified as function parameter. Function returns the value of that key if it's found, or an empty string otherwise.
SetSetupSetting
void SetSetupSetting(str 1, str 2)
Modifies or generates [Setup] section directive given the key (first parameter) and its value (second parameter).
If there is no [Setup] section in &curtrans; (it may happen that function is called before that section in a script), its header (as well as directive itself) is generated by this function.
Please use this function carefully ‐ it should not be called when ISPP is in insert mode (i. e. after &insert; directive).
LowerCase
str LowerCase(str)
Returns a string with the same text as the string passed in its parameter, but with all letters converted to lowercase. The conversion affects only 7-bit ASCII characters between 'A' and 'Z'.
Note: String comparison operators are case-insensitive, so calling LowerCase on strings before comparing is not necessary.
UpperCase
str UpperCase(str)
Returns a string with the same text as the string passed in its parameter, but with all letters converted to uppercase. The conversion affects only 7-bit ASCII characters between 'A' and 'Z'.
EntryCount
int EntryCount(str)
Returns the total number of entries in specified section in &curtrans;. It does not count empty lines or comments. Function takes care of multiple sections with the same name and counts all of them.
GetEnv
str GetEnv(str)
Returns the value of the environment variable whose name is specified as the parameter. Returns an empty string if the variable is not defined.
DeleteFile
void DeleteFile(str)
Marks the specified file for deletion after the compilation has completed. Does not return anything. Also see DeleteFileNow.
DeleteFileNow
void DeleteFileNow(str)
Deletes the specified file. Does not return anything. Also see DeleteFile.
CopyFile
void CopyFile(str ExistingFile, str NewFile)
Copies ExistingFile to NewFile, preserving time stamp and file attributes. If NewFile already exists, it will be overwritten.
FindFirst
int FindFirst(str, int)
Searches the directory specified by first parameter for the first file that matches the file name implied by first parameter and the attributes specified by second parameter. If the file is found, the result is a find handle, that should be used in subsequent calls to FindGetFileName, FindNext, and functions, otherwise the return value is 0.
The first parameter is the directory and file name mask, including wildcard characters. For example, '.\*.*' specifies all files in the current directory).
The second parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants defined in &builtins; when specifying this parameter:
faReadOnly
Read-only files
faHidden
Hidden files
faSysFile
System files
faVolumeID
Volume ID files
faDirectory
Directory files
faArchive
Archive files
faAnyFile
Any file
Attributes can be combined by OR-ing their constants or values. For example, to search for read-only and hidden files in addition to normal files, pass faReadOnly | faHidden as the parameter.
Returns the next entry that matches the name and attributes specified in a previous call to FindFirst. The parameter must be a find handle returned by FindFirst. The return value is non-zero if the function was successful.
FindClose
void FindClose(int)
Terminates a FindFirst/FindNext sequence. The parameter must be a non-zero find handle returned by FindFirst.
This function is obsolete since 1.2. ISPP automatically frees resources allocated in a call to FindFirst.
FindGetFileName
str FindGetFileName(int)
Feed FindGetFileName with the find handle returned by FindFirst to get the name of the file found by the last call to FindFirst or FindNext.
FileOpen
int FileOpen(str)
Opens a text file for reading and returns the file handle (or zero on failure) to be used in subsequent calls to File* functions.
FileRead
str FileRead(int)
Reads the next line in a text file opened with FileOpen. The only parameter should be the file handle returned by FileOpen.
Resets the file pointer to zero, so the subsequent call to FileRead will read the first line of the file. The only parameter should be the file handle returned by FileOpen.
FileEof
int FileEof(int)
Returns zero if the file pointer does not point to the end of the file, or non-zero otherwise. If this function returns non-zero value, subsequent calls to FileRead will fail. The only parameter should be the file handle returned by FileOpen.
FileClose
void FileClose(int)
Closes a file opened using FileOpen. After calling FileClose, the file handle becomes invalid.
Note: opened files which are not closed using this function will be automatically closed after the script has been preprocessed.
SaveStringToFile
int SaveStringToFile(str Filename, str S, int? Append, int? UTF8)
Saves the specified string to the specified file. If Append is non-zero or ommitted and the specified file already exists, it will be appended to instead of overwritten. If UTF8 is non-zero or ommitted, the string will be saved with UTF8 encoding instead of ASCII encoding. Returns non-zero if successful, or zero otherwise.
This function does not automatically write a line break before or after the string. If Append is non-zero or ommitted and the existing file did not end in a line break, the function will effectively append to the existing last line. To avoid this you can put line break characters (using NewLine) before and/or after your string.
#expr SaveStringToFile('c:\filename.txt', NewLine + 'the string' + NewLine)
Returns the current date and time as a string using the specified formatting.
The first parameter is the format string. The second and third parameters are optional and denote the DateSeparator and TimeSeparator parameters explained below.
The following format specifiers are supported:
d
Displays the day as a number without a leading zero (1-31).
dd
Displays the day as a number with a leading zero (01-31).
ddd
Displays the day as an abbreviation (Sun-Sat).
dddd
Displays the day as a full name (Sunday-Saturday).
ddddd
Displays the date using the system's short date format.
dddddd
Displays the date using the system's long date format.
m
Displays the month as a number without a leading zero (1-12). If the m specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.
mm
Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.
mmm
Displays the month as an abbreviation (Jan-Dec).
mmmm
Displays the month as a full name (January-December).
yy
Displays the year as a two-digit number (00-99).
yyyy
Displays the year as a four-digit number (0000-9999).
h
Displays the hour without a leading zero (0-23).
hh
Displays the hour with a leading zero (00-23).
n
Displays the minute without a leading zero (0-59).
nn
Displays the minute with a leading zero (00-59).
s
Displays the second without a leading zero (0-59).
ss
Displays the second with a leading zero (00-59).
t
Displays the time using the system's short time format.
tt
Displays the time using the system's long time format.
am/pm
Uses the 12-hour clock for the preceding h or hh specifier. Displays 'am' for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
a/p
Uses the 12-hour clock for the preceding h or hh specifier. Displays 'a' for any hour before noon, and 'p' for any hour after noon. The a/p specifier can use lower, upper, or mixed case, and the result is displayed accordingly.
/
Displays the date separator character given by the DateSeparator parameter. If DateSeparator is set to an empty string, the system's date separator character will be used instead.
:
Displays the time separator character given by the TimeSeparator parameter. If TimeSeparator is set to an empty string, the system's time separator character will be used instead.
'xx'/"xx"
Characters enclosed in single or double quotes are displayed as-is, and do not affect formatting.
Format specifiers may be written in upper case as well as in lower case letters--both produce the same result.
Returns the date and time of the specified file as a string using the specified formatting.
The first parameter is the file name. The second parameter denotes the format string. The third and fourth parameters are optional and denote the DateSeparator and TimeSeparator parameters as explained in the GetDateTimeString topic.
Gets the SHA-256 hash of the specified file, as a string.
Trim
str Trim(str)
Returns a copy of the specified string without leading and trailing spaces.
StringChange
str StringChange(str, str, str)
Returns a copy of the first string, with all occurrences of the second string changed to the third string.
#define MyString "a ca c"#define MyString2 StringChange(MyString, " ", "b")// MyString2 = 'abcabc'
IsWin64
int IsWin64()
Returns non-zero if the system is running a 64-bit version of Windows that provides the API support Inno Setup requires to perform 64-bit installation tasks, or zero otherwise.
Defined
int Defined(<ident>)int Defined <ident>
Special function. Returns non-zero if the specified identifier is defined with &define; directive.
Using parentheses is optional.
TypeOf
int TypeOf(<ident>)int TypeOf <ident>
Special function. Returns one of predefined TypeOf constants which are declared in &builtins; for the specified identifier.
Using parentheses is optional.
DimOf
int DimOf(<ident>)int DimOf <ident>
Special function. Returns the dimension of the specified identifier.
Using parentheses is optional.
&dim;, &redim;.
GetVersionNumbers
str GetVersionNumbers(str Filename, int *VersionMS, int *VersionLS)
Gets the version numbers of the specified file. Returns the version as a string (in "0.0.0.0" format) if successful, an empty string otherwise.
Declared in &builtins;.
PackVersionNumbers
GetVersionComponents
str GetVersionComponents(str Filename, int *Major, int *Minor, int *Revision, int *Build)
Gets the individual version components of the specified file. Returns the version as a string (in "0.0.0.0" format) if successful, an empty string otherwise.
Declared in &builtins;.
PackVersionComponents
GetVersionNumbersString
str GetVersionNumbersString(str Filename)
Returns the version of the specified file as a string (in "0.0.0.0" format) if successful, an empty string otherwise.
Also see GetStringFileInfo, which can also be used to retrieve file versions using "FileVersion" or "ProductVersion" as the second parameter. The difference is that GetVersionNumbersString takes it from the fixed block of version info, unlike GetStringFileInfo which extracts string from the language specific block.
GetPackedVersion
str GetPackedVersion(str Filename, int *Version)
Gets the packed version of the specified file. Returns the version as a string (in "0.0.0.0" format) if successful, an empty string otherwise.
Always use ComparePackedVersion or SamePackedVersion to compare packed versions.
Declared in &builtins;.
PackVersionComponents
PackVersionNumbers
int PackVersionNumbers(int VersionMS, int VersionLS)
Packs version numbers into a single value.
Always use ComparePackedVersion or SamePackedVersion to compare packed versions.
int ComparePackedVersion(int Version1, int Version2)
Compares Version1 to Version2. The return value is less than 0 if Version1 is less than Version2, 0 if Version1 equals Version2, or greater than 0 if Version1 is greater than Version2.
SamePackedVersion
int SamePackedVersion(int Version1, int Version2)
Compares the packed versions Version1 and Version2 and returns non-zero if they are equal.
UnpackVersionNumbers
void UnpackVersionNumbers(int Version, int *VersionMS, int *VersionLS)
Unpacks a packed version into version numbers.
Declared in &builtins;.
UnpackVersionComponents, PackVersionNumbers
UnpackVersionComponents
void UnpackVersionComponents(int Version, int *Major, int *Minor, int *Revision, int *Build)
Unpacks a packed version into individual version components.
Declared in &builtins;.
UnpackVersionNumbers, PackVersionComponents
VersionToStr
void VersionToStr(int Version)
Returns the specified packed version as a string (in "0.0.0.0" format).
int EncodeVer(int Major, int Minor, int Revision = 0, int Build = -1)
Returns given four version elements encoded to a 32 bit integer number (8 bits for each element, i.e. elements must be within 0...255 range).
Declared in &builtins;.
DecodeVer
str DecodeVer(int Version, int Digits = 3)
Returns given 32 bit integer encoded version decoded to its string representation. The Digits parameter indicates how many elements to show (if the fourth element is 0, it won't be shown anyway).
Declared in &builtins;.
FindSection
int FindSection(str Section = "Files")
Returns the 0-based index of the line following the header of the section, or less than 0 if the section was not found. This function is intended to be used with &insert; directive.
Declared in &builtins;.
FindSectionEnd
int FindSectionEnd(str Section = "Files")
Returns the 0-based index of the line following last entry of the section, or less than 0 if the section was not found. This function is intended to be used with #insert directive.
Declared in &builtins;.
FindCode
int FindCode()
Returns the 0-based index of the line following either the [Code] section header, or the "program" keyword, if any. Returns less than 0 if neither is found.
Declared in &builtins;.
ExtractFilePath
str ExtractFilePath(str PathName)
Returns the directory portion of the given filename, including a trailing backslash. If PathName doesn't contain a directory portion, the result is an empty string.
Declared in &builtins;.
ExtractFileDir
ExtractFileDir
str ExtractFileDir(str PathName)
Returns the directory portion of the given filename, excluding a trailing backslash (unless it is a root directory). If PathName doesn't contain a directory portion, the result is an empty string.
Declared in &builtins;.
ExtractFilePath
ExtractFileExt
str ExtractFileExt(str PathName)
Returns the extension portion of the given filename, NOT including the period character.
Declared in &builtins;.
ExtractFileName
str ExtractFileName(str PathName)
Returns the name portion of the given filename. If PathName ends with a backslash, the result is an empty string.
Declared in &builtins;.
ChangeFileExt
str ChangeFileExt(str FileName, str NewExt)
Changes the extension in FileName with NewExt. NewExt must not contain period.
Declared in &builtins;.
RemoveFileExt
void RemoveFileExt(str FileName)
Removes the extension in FileName.
Declared in &builtins;.
AddBackslash
str AddBackslash(str S)
Appends a backslash to the string, if it's not already there, and returns the result.
Declared in &builtins;.
RemoveBackslashUnlessRoot
str RemoveBackslashUnlessRoot(str S)
Removes the trailing backslash from the string unless the string points to a root directory, and returns the result.
Declared in &builtins;.
Delete
void Delete(str *S, int Index, int Count = MaxInt)
Deletes the specified number of characters beginning with Index from S. S is passed by reference (therefore is modified).
Declared in &builtins;.
Insert
void Insert(str *S, int Index, str Substr)
Inserts specified Substr at Index'th character into S. S is passed by reference (therefore is modified).
Declared in &builtins;.
YesNo
int YesNo(str S)
Returns non-zero if given string is "yes", "true" or "1". Intended to be used with the SetupSetting function.
Declared in &builtins;.
Power
int Power(int X, int P = 2)
Declared in &builtins;.
Min
int Min(int A, int B, int C = MaxInt)
Declared in &builtins;.
Max
int Max(int A, int B, int C = MinInt)
Declared in &builtins;.
SameText
int SameText(str S1, str S2)
Returns non-zero if the given strings are identical, ignoring case.
Declared in &builtins;.
SameStr
int SameStr(str S1, str S2)
Returns non-zero if the given strings are identical, with case-sensitivity.
Message
void Message(str S)
Functional version of pragma message.
Warning
void Warning(str S)
Functional version of pragma warning.
Error
void Error(str S)
Functional version of &error;.
AddQuotes
str AddQuotes(str S)
Adds a quote (") character to the left and right sides of the string if the string contains a space and it didn't have quotes already. This is primarily used when spawning another process with a long filename as one of the parameters.
Is64BitPEImage
int Is64BitPEImage(str FileName)
Returns non-zero if the specified file is a non-32-bit PE image, zero otherwise.
EmitLanguagesSection
void EmitLanguagesSection
Emits a full [Languages] section for all available official languages, including English.
After compilation, see tab Preprocessor Output in the Compiler IDE for the full list of available languages, including their generated names.
Declared in &builtins;.
#expr EmitLanguagesSection
#definedefineFunctionsLocalUser Defined Functions
You can define user defined functions.
A user defined function declaration consists of a formal parameter list and an expression. That expression is evaluated when the function is called (see below). The result of the function call is the result of the expression. The expression can contain parameter names, they are treated as usual variables.
The formal syntax of a user defined function is provided in &define; and &builtins; contains many example functions.
Please note that there must be no space between the function name and opening parenthesis.
Actual parameters for parameters declared as by-reference must be modifiable l-values (in other words, other defined variables or expressions that evaluate to l-values). If the expression modifies by-reference parameter, the variable that is passed as this parameter gets modified. By-value parameters can also be modified by the expression (using assignment operators), but this modification doesn't affect the value of a variable which could be passed as this parameter.
Though a user defined function can only contain one expression, sequential evaluation operators (comma), assignment operators (simple and compound) and conditional operators (?:) can be used to build more complicated functions.
In context of the expression, an additional array named Local is valid. Its elements can be used for temporary storage and reusing values in sequential expressions. Values stored in Local array are neither preserved from call to call (including recursive), nor are they accessible from anywhere except the expression.
#define DeleteToFirstPeriod(str *S) /* user defined function declaration */ \&dsp;Local[1] = Copy(S, 1, (Local[0] = Pos(".", S)) - 1), \&dsp;S = Copy(S, Local[0] + 1), \&dsp;Local[1]
Data typesTypesCommentsExpression Syntax
ISPP uses C/C++-like expression syntax. It supports simple and compound assignment operators, conditional operator, and sequential evaluation operator. Although ISPP is an interpreter, it does support short circuit boolean evaluation and never evaluates expressions (nor calls any user defined functions mentioned in those expressions) that should not be evaluated due to specific rules (for example, when conditional operator is used, always only 2 out of 3 operands are evaluated).
&builtins; contains many example expressions.
ISPP does not support a number of operators (reference, dereference, namespace resolution, member selection, etc.).
ISPP treats an identifier and the equality sign as a name of an parameter, if it is used in parameter list.
Arithmetic division operator (slash) performs integer division, since ISPP does not support floating point math.
ISPP does not check for validity of expressions in certain cases. For example, in conditional expression, "true" operand can be of string type, whereas "false" operand can be of integer type.
String literals can be quoted by both single and double quotes (in both modes ‐ C-style or Pascal-style). If a literal begins with a single quote, it must also end with a single quote. Double quotes may be used in single quoted string without any escaping, and vice versa. Within a string, the character used to quote the string must be escaped (the manner depends on current state of "Pascal-style string literals" parser option, see &pragma;). Also see predefined variable NewLine.
There are three types in ISPP: void, integer, and string. Variable of void type is declared by just specifying its name after &define; directive without any value. Such variables should be used with &ifdef; directive or Defined function.
If "allow undeclared identifiers" parser option is off (the default state, see &pragma;), an error is raised when undefined variable is mentioned. Otherwise, it will be treated as a value of type void.
Void is compatible with integer and string in expressions. For example, you can use addition operator with void and integer operands, in this case void operand will be treated as zero. In conjunction with string, void operand is treated as an empty string.
String comparison operators are case-insensitive.
Comments may be embedded in an expression by using a slash and an asterisk. For example:
#emit Var1 /* this is a comment */ + Var2 /* this is also a comment */
Comments may also be placed at the end of an expression by using a semicolon or two slashes. For example:
#emit Var1 + Var2 ; this is a comment#emit Var1 + Var2 // this is also comment
Please note that line spanning feature is triggered before any further processing, so this is also a valid comment:
#emit Var1 + Var2 ; this is \&dsp;still a comment
Comments may also be placed anywhere by starting a line with two slashes. For example:
// This is a comment
All of the comments listed above are not included in the &translation;, unlike (non ISPP) comments using a semicolon at the start of a line. For example:
#emit Var1 + Var2 ; this comment is not included// This comment is not included; This comment IS included
In ISPP, it is possible to use named parameters when calling user defined function. Given the declaration:
#define MyFunction(int A = 2, int B = 2) A + B
This function can be called specifying parameter names:
#emit MyFunction(A = 5, B = 10)#emit MyFunction(B = 3)#emit MyFunction(B = 10, A = 5)
If a name is specified for one parameter, then all (required) parameters in the list must also be named.
The order of named parameters does not matter.
Because of this extension, an assignment expression must be enclosed in parentheses, if not using extended call syntax, to avoid ambiguity:
#emit MyFunction((MyVar = 5), 10)
In the above example, the equality sign is treated as a direct assignment operator.
Although functions do not have named parameters, it is still required to enclose assignment expressions in parentheses when calling those functions.
By standard rule, comma is used to separate actual parameters. If you need to use sequential evaluation operator, you must include the expression in parentheses:
There are a number of predefined variables provided ISPP:
__COUNTER__
int. Automatically increments each time it is used (afterwards).
__FILENAME__
str. Similar to __PATHFILENAME__, but returns only the filename portion.
__INCLUDE__
str. Returns the current include path (or paths delimited with semicolons) set via #pragma include.
__LINE__
int. Returns the number of the line in the current file.
__OPT_X__
void. Defined if specified option set via #pragma option -x+ is in effect. In place of "X" may be any letter from "A" to "Z". Use Defined function to test whether the variable is defined.
__DIR__
str. Similar to __PATHFILENAME__, but returns only the directory portion, excluding a trailing backslash (unless it is a root directory).
__PATHFILENAME__
str. Returns the full path of the current include file. Empty string for the root script file.
__POPT_X__
void. Defined if specified parser option set via #pragma parseroption -x+ is in effect. In place of "X" may be any letter from "A" to "Z". Use Defined function to test whether the variable is defined.
__WIN32__
void. Always defined.
ISPP_INVOKED
void. Always defined.
ISCC_INVOKED
void. Defined if compilation was invoked using the console-mode compiler, ISCC.exe.
PREPROCVER
int. Returns the 32-bit encoded version of ISPP. Highest byte holds the major version, lowest byte holds the build number.
WINDOWS
void. Always defined.
UNICODE
void. Always defined.
CompilerPath
str. Points to the directory where the compiler is located.
SourcePath
str. Points to the directory where the root script file is located, or the My Documents directory if the script has not yet been saved.
Ver
int. Returns the 32-bit encoded version of Inno Setup compiler. Highest byte holds the major version, lowest byte the minor version.
NewLine
str. Returns the newline character. Declared in &builtins;.
Tab
str. Returns the tab character. Declared in &builtins;.
Line Spanning
By ending lines with ISPP's line spanning symbol preceded with a space, you can split long lines. For example:
#define MyAppName \&dsp;"My Program"
The default line spanning symbol is "\" which can be changed using &pragma;.
privateprotectedpublicvisibilityVisibility of Identifiers
Variables (as well as user defined functions, read "variable or user defined function" anywhere it says "variable" below) can be explicitly defined as "public", "protected", or "private". To define such a variable, its name in its &define; directive should be prepended with one of the visibility keywords:
#define public MyVar 12#define protected MyVar 13#define private MyVar 14
In the example above, none of the last two declarations undefine any of the previous, though they share the same identifier (MyVar). This is because they are declared in different visibilities.
Public variables are ordinary variables accessible from anywhere after the point they are declared.
Protected variables are accessible only in the file they are declared in and in files included by that file via &include; or &file; directives. You can basically think of them as public variables which are automatically undefined once their file has finished.
Private variables are accessible only in the file they are declared in. They are not propagated to any other file, be it included or "parent" file.
Since ISPP does not have semantics of pushing and popping variable value, visibility resolution can be useful.
Note that you cannot explicitly refer to a variable in a specific visibility from expressions. Given the example above, if MyVar is mentioned in expression in declaration file, its identifier refers to private MyVar. If it is mentioned in included file, it refers to protected MyVar. If it is mentioned in one of the files above the declaration file on the include stack (i. e. one of the files from which a chain of &include; directives resulted in processing the declaration file), it refers to public MyVar.
Also note, that if we'd swap last two declarations from the above example, private MyVar would become inaccessible (until protected is undefined) because protected would be declared after it and would take precedence. But it wouldn't undefine its private counterpart.
Each file can set a default visibility, the visibility that will be used when no resolution clause is specified in variable declaration. This can be done using &define; directive, for example:
#define protected
sets protected visibility by default.
The default visibility isn't used when evaluating expressions, it is only used when a variable is defined or undefined without explicitly specifying its visibility. When default visibility is not set, public is assumed by default. Setting default visibility is not propagated on included or parent files.
In user defined function expressions, avoid using identifiers of lower visibility than the one the user defined function is declared in. This may cause "Undeclared identifier" errors if the user defined function is called from another file.
It is recommended that you use appropriate visibility when declaring variables to avoid problems with unexpected redefinition of a variable (for example in included third-party file). If no included files depend on a variable, declare it as private. If they do, but the parent file doesn't, declare it as protected. Declare it as public otherwise. If you're unsure, then protected visibility is the common case.
Example Script
An example script called ISPPExample1.iss is located in a separate folder. Please click the "Inno Setup Example Scripts" shortcut created in the Start Menu when you installed Inno Setup, or open the "Examples" folder in your Inno Setup directory.
Also see &builtins;.
ISPPBuiltins.iss
The ISPPBuiltins.iss file is part of Inno Setup Preprocessor and is automatically installed to root of your Inno Setup folder. This file is automatically included at the start of preprocessing: some of ISPP's functions are actually implemented by this file instead of being built-in. It also contains common declarations such as special constants. The file is a regular Inno Setup Script file so you can use all of its techniques in your own script as well.
Extended Command Line Compiler
The console-mode compiler (ISCC.exe) provides extra parameters to control Inno Setup Preprocessor: