Remove part of an Environment variable path, but not the whole Environment variable!

The problem was that we needed to remove part (i.e., not all of it for obvious reasons!!) of the PATH environment variable during installation (long story, but this path was junk left behind from another install).  As an example, we only wanted to remove the bits in red:

PATH=%SystemRoot%\system32;C:\Program Files\whatever;%SystemRoot%;%SystemRoot%\System32\Wbem;

If you use InstallShield (or Wise for that matter) you’ll see that the GUI doesn’t permit this behaviour.  See the screenshot below:

Remove part of Environment variable

When you set the ‘On Install’ action to ‘Remove’, the ‘Value’ entry gets greyed out and whatever is in there gets deleted.  This to me, implies that the whole Environment variable will be removed.  Yikes!!  That in turn would also imply that the ‘Placement’ entry is irrelevant!  But all is not what it seems….(queue the spooky music)

We can go directly into the Environment table and enter the value we want to remove manually:

Remove Environment Variable

Note that we add “[~]” because the PATH variable also contains other paths, and not just the path we want to remove.  InstallShield places [~] in the value when we set the ‘Placement’ entry to ‘Append’ or ‘Prefix’, so in this instance it is important!

The exclamation  mark in the ‘Name’ entry signifies we want to remove this path on installation only, and the asterisk denotes that PATH is a system variable.