Environment Variable Concept in MSI
Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs.
Example: The TEMP environment variable specifies the location in which programs place temporary files.
Environment Variable can be found under system Properties (My Computer Properties).
To create or modify Environment Variable on the target system, you can use the environment variable view of the editor, and 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.
Two Types of Environment Variables
- System Variables
- User Variables
System Variable:
These variables store information related to resources and settings of any logged user on the target system.
These system Environment variables are stored in Windows Registry
HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ Session Manager\ Environment
User 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.
User Environment variables are stored in Windows Registry
HKEY_CURRENT_USER\Environment
Working with Environment Variables in Wise Package Studio
- Go to Installation Expert.
- Go to Environment Variables.
- Click On Add.
- Then a dialog box will open:
- Give the Name of the Variable in the Name Field.
- In the Value field enter the value to write to the variable.
So that whenever the system finds that variable name it will replace that name with the given value
- In the Operation Field the default will be Set Value on install and Delete on Uninstall or we can change it to our needs
The options available are:
- Set Value on install and Delete on Uninstall
- Create value when installed
- Create value if not present on install
- Delete value on install
- Delete value when uninstalled
- Replacement Field
- Replace current value
- Append at the end of current value
- Insert at the beginning of current value
In the Replacement Field specify whether to append at the end of the current value or Replace a current Value or Insert at the beginning of current value.
If you modify an existing environment variable value, such as PATH, it is essential to set Append at the end of current value not Replace the current value.
Working with Environment Variables in Installshield Admin Studio
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:
- In the Environment Variable view, right Click the Environment Variable icon and select Add Environment Variable.
- In the Component Field, select the component with which you want to associate the variable.
- 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].
- In the On Install field specify whether to set, create, or remove the variable on the target system during the installation.
- 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.
- In the On Uninstall field specify whether to Remove the variable data or to Leave the variable data during the uninstallation.
- 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.



Options: Env Variable
A good post.
Its always adviced that we use these following options while setting an environment variable.
"Set Value on install and Delete on Uninstall " and "Append at the end of current value"
This setting will keep the machine in the safe state always.
Cheers'
Vijay
Microsoft MVP [Setup-Deploy]
Weblog: www.msigeek.com
Good Advice regarding best
Good Advice regarding best practices, but the option "Set Value on install and Delete on Uninstall " and "Append at the end of current value" generally is best for PATH environment variable and not for application specific variables. If your application is creating an environment variable then you can replace the value. This is because if there is an older version which has different environment variable set and if that is not getting deleted while uninstall then you have to make it delete.
so it actually depends on application to application.
You can definitely use the above said values in PATH variable.
Piyush Nasa
Altiris Certified Professional (ACP)
Great post!
Hi,
Hope you will have an answer for me.
I used your post to add couple of environment variables to my setup.
You said that "by default the environment variable data are installed when a component is installed and removed when the component is removed".
That means that they are set on InstallFiles, correct?
I really attached them to a component containg files.
What I really want to do is to set those variables, then reboot the system and automatically restart the setup.
I managed to restart the setup automatically but it starts the whole process from the start.
For this I would prefer that the environment setting action will be the first one in the sequence (maybe just after InstallInitialize).
Is that possible?
Many thanks!
Would you like to reply?
Login or Register to post your comment.