Inno Setup lets you set environment variables via the [Registry] sections (by setting registry key which correspond to environment variable)
However, sometimes you don’t just wanna set an environment variable. Often, you wanna modify it. For example: upon installation, one may want to add/remove a directory to/from the PATH environment variable.
How can I modify the PATH environment variable from within InnoSetup?
The path in the registry key you gave is a value of type
REG_EXPAND_SZ. As the Inno Setup documentation for the [Registry] section states there is a way to append elements to those:So to append to the path a registry section similar to this may be used:
which would append the “C:\foo” directory to the path.
Unfortunately this would be repeated when you install a second time, which should be fixed as well. A
Checkparameter with a function coded in Pascal script can be used to check whether the path does indeed need to be expanded:This function reads the original path value and checks whether the given directory is already contained in it. To do so it prepends and appends semicolon chars which are used to separate directories in the path. To account for the fact that the searched for directory may be the first or last element semicolon chars are prepended and appended to the original value as well:
Note that you may need to expand constants before you pass them as parameter to the check function, see the documentation for details.
Removing this directory from the path during uninstallation can be done in a similar fashion and is left as an exercise for the reader.