Write an Environment Variable
This action lets you set a persistent Windows environment variable. It writes the value to the Windows registry and notifies running processes of the change via WM_SETTINGCHANGE, so applications can pick up the new value without a reboot.
You can choose to write to the user environment (available only to the current user) or the system environment (available to all users on the machine). Writing to the system environment requires administrator privileges.
| Property Name | Data Type | Description |
|---|---|---|
| VarName | String | The name of the environment variable to set (e.g., JAVA_HOME, MY_APP_DIR). You can use variables. |
| Value | String | The value to assign to the environment variable. You can use variables such as %DESTPATH%. |
| Scope | TEnvVarScope | evsUser writes to the current user’s environment (HKEY_CURRENT_USER\Environment). evsSystem writes to the system environment (HKEY_LOCAL_MACHINE\...\Environment) and requires admin rights. Default is evsUser. |
| ExpandableString | Boolean | When true, the value is stored as REG_EXPAND_SZ (expandable string), allowing references to other environment variables like %SystemRoot%. When false (default), the value is stored as REG_SZ (regular string). Use REG_EXPAND_SZ when appending to variables like PATH. |
| AddUninstRef | Boolean | When true (default), the environment variable will be removed by the uninstaller — but only if the variable did not already exist before the installer ran. If the variable already existed (e.g., PATH), the uninstaller will leave it untouched to avoid breaking the system. |
Example 1: Set a new application directory variable
Section titled “Example 1: Set a new application directory variable”To create a user environment variable MY_APP_HOME pointing to the installation directory:
- Set
VarNametoMY_APP_HOME - Set
Valueto%DESTPATH% - Set
ScopetoevsUser - Leave
ExpandableStringasFalse - Leave
AddUninstRefasTrue— the variable will be removed on uninstall since it did not exist before
Example 2: Add to system PATH
Section titled “Example 2: Add to system PATH”To add your application’s bin directory to the system PATH:
- First, use a Modify a variable action to read the current
PATHvalue into a variable (e.g.,%OLDPATH%) - Then use this action:
VarName=PathValue=%OLDPATH%;%DESTPATH%\binScope=evsSystemExpandableString=True(PATH uses expandable strings)AddUninstRef=False(since PATH already exists, set this to False)
Action Catalog Browse all available custom actions.