Variables are used to store a value in memory while a script is processing.
Variables consist of a unique name used to identify the variable and must be enclosed in percent signs %
. Variable names are case insensitive, so %myVar%
is the same as %MYVAR%
.
Variables can be defined in several different ways:
Predefined variables defined in the script's [Variables] section
[Variables]
%myVar%="Hello World!"
Dynamically at runtime using the Set
and AddVariables
commands
Set,%myVar%,12345
AddVariables,%ScriptFile%,AlternativeVariables
As a return value of a command such as StrFormat
, Math
, or RegRead
.
StrFormat,Left,"Hello World!",5,%result%
It is possible that local variable may share the same name with a project global variable. In the event a name collision occurs the following order will be used to determine the value to be use within the script.
- Fixed Variables
- Local Variables
- Global Variables
When the compatibility option Overridable Fixed Variables
is enabled the following search order is used.
- Local Variables
- Global Variables
- Fixed Variables
Fixed Variables are reserved variables that are populated by PEBakery and cannot be overwritten*.
*The Winbuilder compatibility option Overrideable Fixed Variables
may be enabled for compatibility with older projects in transition from Winbuilder to PEBakery, however it is recommended that the project be updated as quickly as possible to remove this unsafe behavior.
Variable | Description |
---|---|
%PEBakery% | Always returns TRUE if the script is running with PEBakery. Used for cross-builder compatibility with scripts containing features not implemented in Winbuilder. |
%BaseDir% | The directory where PEBakery was launched from. This variable is used extensively as a reference point for determining the relative paths of important directories such as Projects , Target , and Cache/Workbench . Ex. %BaseDir%\Target |
%Version% | For compatibility with scripts designed for Winbuilder this variable always returns 082 . |
%EngineVersion% | Returns the machine friendly version of the PEBakery engine. |
%PEBakeryVersion% | Returns the human friendly version of the PEBakery engine. |
%ProjectTitle% | The name of the project as defined in script.projects Main section. |
%ProjectDir% | The full path to the directory containing the project (script.project). |
Variable | Description |
---|---|
%ScriptDir% | The full path to the directory containing the currently running script. |
%ScriptFile% | The full path of the currently running script. |
%ScriptTitle% | The title of the currently running script as defined by the script's [Main] section. |
Fixed environment variables are included only for compatibility with Winbuilder and must be enabled with the compatibility option Enable Environment Variables
. If you need to retrieve information about the local operating system's environment it is recommended to use the more flexible and accurate System,GetEnv
command instead.
Variable | Description |
---|---|
%ProcessorType% | One of the following: |
586 - Intel-based 32-bit processor architecture. | |
8664 - Intel-based 64-bit processor architecture. | |
Arm - 32-bit ARM processor architecture. PEBakery Only | |
Arm64 - 64-bit ARM processor architecture. PEBakery Only | |
Unknown - Any other architecture. | |
%ProgramFilesDir% | The path of the local operating system's Program Files directory. |
%ProgramFilesDir_x86% | If The path of the local operating system's Program Files (x86) directory (x64 OS only). |
%TempDir% | The path of the local operating system's Temp directory. |
%UserName% | The name of the currently logged in user. |
%UserProfile% | The path of the logged in user's home directory. |
%WindowsDir% | The path of the local operating system's Windows directory. |
%WindowsVersion% | The local operating system's version number. |
Local variables are "visible" only to the currently running script. All variables are created in the local scope unless explicitly defined otherwise.
Some PEBakery commands return the status of various commands via pre-defined variables. It is advised not to use these variable names in your scripts in order to prevent them from being overwritten.
Variable | Command | Description |
---|---|---|
%ExitCode% | ShellExecute, ShellExecuteDelete | Contains the Exit Code returned by the most recent ShellExecute command. |
Global variables are available to the entire project and can be defined by:
Script.Project's [Variables] section
[Variables]
%myVar%=12345
The GLOBAL
keyword
Set,%myVar%,12345,GLOBAL
The following variables are included for compatibility with WinBuilder, which stores them in the [Main]
section of script.project
.
If PathSetting=True
is defined in script.project
then the following variables are set to the value of the matching key in script.project's
[Main]
section. If PathSetting=False
they will be ignored.
Variable | PathSetting | Value |
---|---|---|
%SourceDir% | True | Value of SourceDir= |
False | undefined | |
%TargetDir% | True | Value of TargetDir= |
False | undefined | |
%ISOFile% | True | Value of ISOFile= |
False | undefined |