Root > Integral parts > Variables

Variables

Previous pageReturn to chapter overviewNext page   

Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. They can be said in some sense to create the operating environment in which a process runs. For example, an environment variable with a standard name can store the location that a particular computer system uses to store temporary files - this may vary from one computer system to another. A process which invokes the environment variable by (standard) name can be sure that it is storing temporary information in a directory that exists and is expected to have sufficient space.

 

You can use environment variables in any text values in your project settings. You can insert variable by using "Variables" window. Variable is inserted as special tag. When you run your application at run-time, any variable value will be replaced with actual value, which is calculated at run-time.

 

For example, if you set your folder for saving bug-report to "%APPDATA%\MyBugReports" then your bug reports may be saved to (few examples):

C:\Users\UserName\AppData\Roaming\MyBugReports\
C:\Documents and Settings\UserName\Application Data\MyBugReports\
C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\MyBugReports\
C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\MyBugReports\

Depending on real value of %APPDATA% variable at run-time.

 

Note: variables names are case-insensitive.

 

 

EurekaLog

EurekaLog expands system variables set by the following special pseudo-variables. They can be used in the same way as any other usual environment variable.

 

Warning: don't forget that you need to enclose variable name into '%', for example for _BugID variable you must use '%_BugID%' text (without quotes).

 

EurekaLog's variables:

_ExceptType - exception's class. For example: 'EAccessViolation'. It will be replaced with empty string if there is no exception in question.
_ExceptMsg - exception's message. For example: 'Access violation at address 00000000. Read at address 000000'. It will be replaced with empty string if there is no exception in question.
_CallStack - compact call stack of exception (multi-line). It will be replaced with empty string if there is no exception in question.
_BugID - exception's BugID. For example: '47A10000'. It will be replaced with empty string if there is no exception in question.
_Reproduce - "steps to reproduce" text as it was entered by user (in error dialog). This is arbitrary multi-line text. Empty by default.
_BugReport - full bug report text (multi-line). It will be replaced with empty string if there is no exception in question.
_LineBreak - the simple line break (#13#10 or #10 - depending on your platform). It's useful to enter multi-line texts in single-line edit control.
_XYZModulePath - path to executable file without trailing path delimiter. For example: 'C:\Program Files\My Product'. XYZ part selects module in question.
_XYZModuleName - executable file name. For example: 'Project1.exe'. XYZ part selects module in question.
_XYZModuleDesc - description of executable file. It's extracted from file's version information. XYZ part selects module in question.
_XYZModuleVer - version of executable file. For example: '1.0.2.0'. It's extracted from file's version information. XYZ part selects module in question.

 

Where XYZ can be:

Main - .exe file of running process.
Except - module which has raised exception (applicable only if there is exception in question).
This - your project (.exe or .DLL).

 

If your project is .exe - "This" will be the same as "Main". If exception was raised in your project (and not in some other DLL) - "Except" will be the same as "This". If your application consists only of single .exe and never catches exceptions from other DLLs - then all 3 values will be the same. We suggest to use "Except" case as default (e.g. like %_ExceptModuleName%).

 

The following variables are available only for IDE and compilation options (like pre/post build events, external configuration path, localization path, etc.):

_IDEProject - file name of project file. Like C:\Projects\MyProject.dpr for Delphi 7 or C:\Projects\MyProject.dproj for Delphi XE.
_IDESource - file name of project source file. Like C:\Projects\MyProject.dpr for both Delphi 7 and Delphi XE.
_IDEConfig - file name of options file. Like C:\Projects\MyProject.dof for Delphi 7, C:\Projects\MyProject.dproj for Delphi XE or C:\Projects\Options\External.eof for external configuration.
_IDETarget - final compiled executable file. Like C:\Projects\MyProject.exe or C:\Projects\MyProject.dll.
_IDESrc - folder with trailing path delimiter, containing project's files. Like C:\Projects\
_IDEDst - folder with trailing path delimiter, containing compiled executable. Like C:\Projects\ for Delphi 7 or C:\Projects\Win32\Debug\ for Delphi XE.

 

System/Windows variables:

CSIDL_ABC - special folder identified by CSIDL ABC.
FOLDERID_DEF - special folder identified by FOLDERID DEF.

 

Where ABC can be:

Name of CSIDL value. For example: APPDATA or COMMON_APPDATA or LOCAL_APPDATA, so full variable name will be %CSIDL_COMMON_APPDATA%, %CSIDL_APPDATA% or %CSIDL_LOCAL_APPDATA%. See this topic in MSDN to get the full list of all possible CSIDL values.
Numeric value of CSIDL. For example: 26 or $001a, so full variable name will be %CSIDL_26% or %CSIDL_$1a%.

 

See also: %APPDATA% and other Windows environment variables below.

 

Where DEF can be:

Name of FOLDERID value. For example: RoamingAppData, ProgramData, LocalAppData or LocalAppDataLow, so full variable name will be %FOLDERID_RoamingAppData%, %FOLDERID_ProgramData%, %FOLDERID_LocalAppData% or %FOLDERID_LocalAppDataLow%. See this topic in MSDN to get the full list of all possible FOLDERID values.
GUID-value of FOLDERID. For example: {3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}, so full variable name will be %FOLDERID_{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}%.

 

See also: %APPDATA% and other Windows environment variables below.

 

Note: FOLDERID values are available only for Windows Vista+. CSIDL values are available on all Windows platforms.

 

Warning: if variable doesn't exist - it will be replaced with empty string. Be careful to use variables which are available only on certain platform or environment.

 

You can also use any system environment variable apart from EurekaLog-specific variables above. Just use %system-variable-name% - where system-variable-name is a name of system variable (see below). You can use any system variable - even if it's not listed in "Variables" window. "Variables" window lists only build-in pseudo-variables and some commonly used system variables.

 

 

Windows

In Windows, the set command without any arguments displays all environment variables along with their values:

 

 

Example of environment variables list

 

To set a variable to a particular value, use:

 

set VARIABLE=value

 

However, this change is temporal, as "set" command makes changes to current environment variables, changes are not saved to system settings - thus such changes will be lost after restart.

 

Permanent changes to the environment variable can be achieved through GUI (Control Panel/System/Advanced/Environment Variables), using the setx.exe application, and editing the registry - HKCU\Environment (for user specific variables) or HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment (for system variables) - this is not recommended for novices. The setx.exe application is part of Windows since Windows Vista. It is also a part of Windows Resource Kit for previous Windows versions.

 

Use:

 

setx VARIABLE value

 

to change permanently user's (local) environment variables. Use:

 

setx VARIABLE value /m

 

to change permanently system's (global) environment variables. The later requires administrative access.

 

Please note that environment variables are stored per-process and are inherited from parent processes. Changing environment variables in system configuration will not change environment variables of already running processes. For example, using "set" command in console will change environment block of console process - because "set" is internal command. On the other hand, using "setx" will not alter environment block of console process, because setx.exe is an external application and have no access to environment variables of parent process. In most cases processes has to be restarted to get notified of changes in stored environment variables. However, some processes may react to broadcasts of WM_SETTINGCHANGE message, and reload/update environment variable block.

 

Use SetEnvironmentVariable function to alter environment variable(s) in your own process.

 

To see the current value of a particular variable, use:

 

echo %VARIABLE%

 

or

 

set VARIABLE

 

Use GetEnvironmentVariable function to retrieve value of environment variable in your own process.

 

To delete a variable, the following command is used:

 

set VARIABLE=

 

or

 

setx VARIABLE ""

 

setx VARIABLE "" /m

 

(depending on local/global scope)

 

Unfortunately, the setx.exe application will only clear variable, but not delete it completely. However, the final result is the same (e.g. empty value).

 

Note: The names of environment variables are case-insensitive in Windows.

 

Important Note: Windows environment variables are specific to user account. Each user account has its own set of variables. EurekaLog will use variables of user running your executable. For example, if you are writing a Win32 Service application - such application is run by "Local System" account by default. "Local System" account has its own environment variables values, which are different from environment variables values of your current interactive user account.

 

Standard Windows environment variables

1. General pseudo-variables - these variables generally expand to discrete values, such as the current working directory, the current date, or a random number. They look like environment variables, but they are not:
%CD% - this variable points to the current directory. Equivalent to the output of the command cd when called without arguments.
%DATE% - this variable expands to the current date. The date is displayed according to the current user's date format preferences. EurekaLog also offers %DATEFMT% pseudo-variable, which represents current date in fixed format.
%ERRORLEVEL% - this variable points to the current error level. If there was an error in the previous command, this is what you need to check against to find out about that. Not applicable outside of cmd shell.
%RANDOM% - this variable returns a random number between 0 and 32767.
%TIME% - this variable points to the current time. The time is displayed according to the current user's time format preferences. EurekaLog also offers %TIMEFMT% pseudo-variable, which represents current time in fixed format.

 

2. System path variables - these variables refer to locations of critical operating system resources, and as such generally are not user-dependent:
%AllUsersProfile% (%PROGRAMDATA% for Windows Vista, Windows 7) - expands to the full path to the All Users profile directory. This profile contains resources and settings that are used by all system accounts. Shortcut links copied to the All Users' Start menu or Desktop folders will appear in every user's Start menu or Desktop, respectively.
%ComSpec% this variable contains the full path to the command processor, cmd.exe.
%PATH% - this variable contains a semicolon-delimited (do not put spaces in between) list of directories in which the command interpreter will search for an executable file that matches the given command.
%ProgramFiles% - this variable points to Program Files directory, which stores all the installed applications. The default is C:\Program Files. In 64-bit editions of Windows (XP, 2003, Vista), there are also %ProgramFiles(x86)% which defaults to C:\Program Files (x86) and %ProgramW6432% which defaults to C:\Program Files. The %ProgramFiles% itself depends on whether the process requesting the environment variable is itself 32-bit or 64-bit (this is caused by Windows-on-Windows 64-bit redirection).
%CommonProgramFiles% - this variable points to Common Files directory.
%SystemDrive% - is the drive upon which the system folder was placed. Also see next item.
%SystemRoot% - is the location of the system folder, including the drive and path. The drive is the same as %SystemDrive% and the default path on a clean installation depends upon the version of the operating system. By default, on a clean installation: Windows NT 5.1 (Windows XP) and newer versions use \WINDOWS. Windows NT 5.0 (Windows 2000) use \WINNT.
%TEMP% and %TMP% - these variables contain the path to the directory where temporary files should be stored.
%WinDir% - this variable points to the Windows directory. It is identical to the %SystemRoot% variable above on modern systems.

 

3. User management variables - these variables store information related to resources and settings owned by various user profiles within the system. As a general rule, these variables do not refer to critical system resources or locations that are necessary for the OS to run:
%AppData% - contains the full path to the Application Data folder of the logged-in user.
%LOCALAPPDATA% - this variable is the temporary files of Applications. Its uses include storing of Desktop Themes, Windows Error Reporting, Caching and profiles of web browsers.
%UserDomain% - holds the name of the Workgroup or Windows Domain to which the current user belongs. The related variable, %LOGONSERVER%, holds the hostname of the server that authenticated the current user's logon credentials (name and password). For Home PCs, and PCs in a Workgroup, the authenticating server is usually the PC itself. For PCs in a Windows Domain, the authenticating server is a domain controller (a primary domain controller, or PDC, in Windows NT 4-based domains).
%UserName% - is the name/login of current user.
%UserProfile% - is the location of the current user's profile directory, in which is found that user's HKCU registry hive (NTUSER). Users can also use the %USERNAME% variable to determine the active users login identification.

 

Notes:

Some variables exist only on modern versions of Windows and aren't available on old/previous versions.
Some variables exist only in 64-bit edition of Windows. For example, %ProgramW6432% are not supported in 32-bit operating systems.
Some of the variables depend on the bitness of the caller and thus lead to different results, depending on whether the caller is 32- or 64-bit application. For example, program installers typically use %ProgramFiles% to install the application in the Program Files folder. Thus, the 64-bit installer will install the program in C:\Program Files\, and 32-bit installer - in C:\Program Files (x86)\.
Some variables are valid only for 32-bit or 64-bit processes. Refer to MSDN for more information.
CSIDL and FOLDERID values are special EurekaLog's pseudo-variables. They always use WinAPI to obtain folder's path. Variables like %APPDATA% are usual environment variables, so they can be altered by parent process.

 

Important Note: Windows environment variables are specific to user account. Each user account has its own set of variables. EurekaLog will use variables of user running your executable. For example, if you are writing a Win32 Service application - such application is run by "Local System" account by default. "Local System" account has its own environment variables values, which are different from environment variables values of your current interactive user account.

 

Examples of default values for Windows environment variables

 

Variable

Windows XP and below

Windows Vista and above

%ALLUSERSPROFILE%

C:\Documents and Settings\All Users

C:\ProgramData

%APPDATA%

C:\Documents and Settings\{username}\Application Data (normal user account)

C:\WINDOWS\system32\config\systemprofile\Application Data\ (local system account)

C:\Users\{username}\AppData\Roaming (normal user account)

C:\WINDOWS\system32\config\systemprofile\AppData (local system account)

%COMPUTERNAME%

{computername}

{computername}

%COMMONPROGRAMFILES%

C:\Program Files\Common Files

C:\Program Files\Common Files

%COMMONPROGRAMFILES(x86)%

C:\Program Files (x86)\Common Files

C:\Program Files (x86)\Common Files

%COMSPEC%

C:\Windows\System32\cmd.exe

C:\Windows\System32\cmd.exe

%HOMEDRIVE%

C:

C:

%HOMEPATH%

\Documents and Settings\{username}

\Users\{username}

%LOCALAPPDATA%


C:\Users\{username}\AppData\Local

%LOGONSERVER%

\\{domain_logon_server}

\\{domain_logon_server}

%PROGRAMFILES%

C:\Program Files

C:\Program Files

%PROGRAMFILES(X86)%

C:\Program Files (x86)

C:\Program Files (x86)

%SystemDrive%

C:

C:

%SystemRoot%

C:\Windows

C:\Windows

%TEMP% and %TMP%

C:\Documents and Settings\{username}\Local Settings\Temp (normal user account)

C:\Windows\Temp (local system account)

C:\Users\{username}\AppData\Local\Temp (normal user account)

C:\Windows\Temp (local system account)

%USERDOMAIN%

{userdomain}

{userdomain}

%USERNAME%

{username}

{username}

%USERPROFILE%

C:\Documents and Settings\{username}

C:\Users\{username}

%WINDIR%

C:\Windows

C:\Windows

%PUBLIC%


C:\Users\Public

%PROGRAMDATA%


C:\ProgramData

%PSModulePath%


C:\system32\WindowsPowerShell\v1.0\Modules\

 

 

See also:




Send feedback... Build date: 2018-11-26
Last edited: 2018-06-14
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/variables.php