13

I have used the following wix fragment to update "PATH" environment variable.

<DirectoryRef Id="MyDir">
   <Component Id ="setEnviroment" 
                           Guid=" xxxxx">
            <CreateFolder />
             <Environment Id="SET_ENV"
                                       Action="set"                                                                                          
                                         Name="PATH"
                                        Part="last"       
                                       Permanent="no" 
                                        System="yes" 
                         Value="[INSTALLLOCATION]" />
       </Component>
</DirectoryRef>
<Feature Id="Feature3" Title="3Feature"   
             Level="1" 
              Absent="disallow"
               AllowAdvertise="no">
           <ComponentRef Id="setEnviroment"/>
</Feature>
<InstallExecuteSequence>
    <WriteEnvironmentStrings/>
<InstallExecuteSequence/>

This was working initially but now it doesn't update the environment variable. The Verbose log shows the execution of this action and return value 1. Checked after restarting machine. In the log for action FeaturePublish For Feature3 there is garbage value but Installation is successful. Request your help in this...... Thanks a lot....

user1512683
  • 131
  • 1
  • 3

2 Answers2

18

I think you are using INSTALLLOCATION where you mean to use INSTALLDIR. Here is a working example which updates the PATH environment var with the installation directory of the new app.

<Environment 
  Id="PATH" 
  Name="PATH" 
  Value="[INSTALLDIR]" 
  Permanent="yes" 
  Part="last" 
  Action="set" 
  System="yes" />

If do intend to use INSTALLLOCATION, and have it defined elsewhere, then please post the rest of your code and we will go further down the rabbit hole.

Nathan Boyd
  • 579
  • 3
  • 8
  • 1
    I'm trying to set env variable using this answer but without success: I can't find right place for `Environment`. Could somebody explain where should I place `Environment` tag in my wxs file: gist.github.com/pyeremenko/891eceb779197e4be240 – Peter Yeremenko May 18 '15 at 08:25
  • 1
    @PeterYeremenko: `` is supposed to be placed into a `` tag. – c00000fd Feb 13 '16 at 02:25
  • 2
    [Official Wix documentation](https://www.firegiant.com/wix/tutorial/com-expression-syntax-miscellanea/environmentally-friendly/) for `Environment` tag. – user3613932 Jul 25 '18 at 04:46
0

I needed to use INSTALLFOLDER instead, to get it working.

<Environment 
  Id="PATH" 
  Name="PATH" 
  Value="[INSTALLFOLDER]" 
  Permanent="yes" 
  Part="last" 
  Action="set" 
  System="yes" />