Skip to content

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 NameData TypeDescription
VarNameStringThe name of the environment variable to set (e.g., JAVA_HOME, MY_APP_DIR). You can use variables.
ValueStringThe value to assign to the environment variable. You can use variables such as %DESTPATH%.
ScopeTEnvVarScopeevsUser 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.
ExpandableStringBooleanWhen 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.
AddUninstRefBooleanWhen 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:

  1. Set VarName to MY_APP_HOME
  2. Set Value to %DESTPATH%
  3. Set Scope to evsUser
  4. Leave ExpandableString as False
  5. Leave AddUninstRef as True — the variable will be removed on uninstall since it did not exist before

To add your application’s bin directory to the system PATH:

  1. First, use a Modify a variable action to read the current PATH value into a variable (e.g., %OLDPATH%)
  2. Then use this action:
    • VarName = Path
    • Value = %OLDPATH%;%DESTPATH%\bin
    • Scope = evsSystem
    • ExpandableString = True (PATH uses expandable strings)
    • AddUninstRef = False (since PATH already exists, set this to False)