The "Environment" Command |
This command creates or updates environment variables. To do this it populates the MSI "Environment" table.
You should use the Path command to manipulate "path like" environment variables.
The macro takes these parameters:
You should use "*VALUE" if you have a VBSCRIPT expression which resolves to a string (use "cstr()" if you get a type mismatch).
The default for this parameter can be set via the DEFAULT_ENVIRON_SYSTEM macro. This is initially "Y".
This parameter should be passed a comma separated list of one or more of the following values:
The default for this parameter can be set via the DEFAULT_ENVIRON_HOW macro. The initial value is "SET_DURING_INSTALLATION, DELETE_ON_UNINSTALL".
User Logoff or Reboot Required? |
To pick up the changed environment variables the user may need to logoff and logon (user environment variables) or reboot (system environment variables). This is because the variables are per-process and will not normally change until the process is restarted at which time it typically inherits the parent processes environment.
Windows Installer will broadcast the "WM_SETTINGCHANGE" message (lParam set to the string "Environment") to all top level windows so that these processes have the opportunity to update their per-process environment details if they so wish. It is a known Windows "feature" that the SCM (services) doesn't handle this message.
As a diagnostic aid, the "PROCESS EXPLORER" tool can show you the "process hierarchy" as well as each processes environment.
EXAMPLES |
<$Component "Environment" Directory_="<$AnyDir>" LM="Y"> ;--- Test environment macro (create in install, remove in uninstall) ----- <$Environment Name="EnvVarLit" VALUE="Value4EnvVar1"> ;;Assign literal <$Environment Name="EnvVarExp" *VALUE="WeekDayName(WeekDay(date()))"> ;;Assign result of VBSCRIPT expression <$/Component> <$Component "SomeExistingComponentJustAsAnExampleOfHowToDoIt"> ;--- Test PATH macro ----------------------------------------------------- <$Path "C:\Some\Path"> ;;Normally update "PATH" <$Path "[TARGETDIR]"> ;;Refer to MSI directory/property <$Path ".REX" NAME="PATHEXT"> ;;Update another type of "path like" environment <$/Component>