Skip to main content

Environment Variables

All details about environment variables and their use in an installer.

Format

Environment Variables in Windows are denoted with percent signs (%) surrounding the name:
%name%

echo

To display an environment variable's value in cmd.exe, type echo %name%.
C:\>echo %USERPROFILE%
C:\Users\Daniel

set

To create/set a variable, use set varname=value:
C:\>set FunnyCatPictures=C:\Users\Daniel\Pictures\Funny Cat Pictures

C:\>set FunnyCatPicturesTwo=%USERPROFILE%\Pictures\Funny Cat Pictures 2

Environment variables set in this way are available for (the rest of) the duration of the Command Prompt process in which they are set, and are available to processes that are started after the variables were set.

setx

To create/set a variable permanently, use setx varname "value":
C:\>setx FunnyCatPictures "C:\Users\Daniel\Pictures\Funny Cat Pictures"

[Restart CMD]

C:\>echo %FunnyCatPictures%
C:\Users\Daniel\Pictures\Funny Cat Pictures
Unlike set, there is no equals sign and the value should be enclosed in quotes if it contains any spaces. 

List of Windows Environment Variables

Here is a list of default environment variables, which are built into Windows. Some examples are: %WINDIR%%SystemRoot%%USERPROFILE%, and %APPDATA%. Like most names in Windows, these are case-insensitive.

System-wide environment variables are kept in the Registry, HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment, and loaded at system boot.
User environment is kept in HKCU\Environment and loaded during user logon.


Envrionment Table:
Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. It can be found under system Properties (My Computer Properties).
Example: The TEMP environment variable specifies the location in which programs place temporary files.

environment variable changes must be associated with a component, by default the environment variable data are installed when a component is installed and removed when the component is removed.
Environment Variables can be viewed in the Installshield Editor View, under Installation Designer, under view list item "System Configuration":
To write Environment Variable data to the target system:
1.       In the Environment Variable view, right Click the Environment Variable icon and select Add Environment Variable.
2.       In the Component Field, select the component with which you want to associate the variable.
3.       In the Value field, enter the value to write to the variable, as with registry and INI file data, you can expand the value of a windows installer property using the format [PropertyName].
4.       In the On Install field specify whether to set, create, or remove the variable on the target system during the installation.
5.       In the Placement field specify whether to append the value to any existing data in the variable, or whether to replace any existing data, If you intend to modify the PATH variable or any other existing environment variable, you should select to append or prepix and not replace the existing variable data.
6.       In the On Uninstall field specify whether to Remove the variable data or to Leave the variable data during the uninstallation.
7.       In the Type field, select System to create a system Environment Variable it will be Available to any logged user on the target system, or select User to create a User environment variable it will be available only to the User who ran the installation program.

Environment
This is the primary key of the table and is a non-localized token.
Name
This column is the localizable name of the environment variable. The key values are written or removed depending upon which of the characters in the following table are prefixed to the name. There is no effect in the ordering of the symbols used in a prefix.

Prefix
Description
=
Create the environment variable if it does not exist, and then set it during installation. If the environment variable exists, set it during the installation.
+
Create the environment variable if it does not exist, then set it during installation. This has no effect on the value of the environment variable if it already exists.
-
Remove the environment variable when the component is removed. This symbol can be combined with any prefix.
!
Remove the environment variable during an installation. The installer only removes an environment variable during an installation if the name and value of the variable match the entries in the Name and Value fields of the Environment table. If you want to remove an environment variable, regardless of its value, use the '!' syntax, and leave the Value field empty.
*
This prefix is used with Windows 2000 to indicate that the name refers to a system environment variable. If no asterisk is present, the installer writes the variable to the user's environment. This symbol can be combined with any prefix. A package that is used for installation in the per-machine installation context should write environment variables to the machine's environment by including * in the Name column. For more information, see Remarks.
=-
The environment variable is set on install and removed on uninstall. This is the usual behavior.
!-
Removes an environment variable during an install or uninstall.
=+
!+
!=
These are not a valid prefixes

Comments