39

I still don't know how to add the installdir into the PATH of the Windows System Variables after I went through the WIX tutorial.

I tried to use

  Environment Id='UpdatePath' Action='create' Name='PATH'  System='yes' Value='[INSTALLDIR]' 

But there was no change in the Path after I installed the program. I can hardly find sample code of WIX anywhere. Please help me, thanks a lot!

Ray
  • 1,893
  • 7
  • 22
  • 24

3 Answers3

55

You should be able to use:

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

This should add a new entry to the environment path, set to [INSTALLDIR].

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • 31
    Setting `Permanent="no"` will remove the appended part (but not the entire value) on uninstall. – Kevin Smyth Nov 18 '11 at 16:05
  • 6
    note INSTALLDIR is not a magic word - it needs to match the id of a directory which can be whatever you like (doesnt even need the caps, although they do have a special meaning in wix!) – JonnyRaa Jan 07 '14 at 15:14
  • This isn't working for me. When I echo my %PATH% variable it is unchanged. Can anyone post a bit more of the context? I've got it in a DirectoryRef per @Deqing's answer below, but I'm still not having any luck. – stranger Feb 23 '17 at 21:08
  • [Wix Official Documentation Basic](https://www.firegiant.com/wix/tutorial/com-expression-syntax-miscellanea/environmentally-friendly/) and [Wix Official Documentation Detailed](http://wixtoolset.org/documentation/manual/v3/xsd/wix/environment.html) for `Environment` tag. – user3613932 Jul 25 '18 at 04:55
  • @KevinSmyth: If we set `Permanent="no"` what happens if more values from other installs are appended to the path environment variable by the time the user hits uninstall? Is the correct value still removed from the path environment variable? – user3613932 Jul 25 '18 at 05:03
  • With `Permanent="no"`, I tried uninstalling after adding more values to a environment variable manually. The correct value was removed after the uninstall leaving the other values untouched. Works great. – user3613932 Jul 25 '18 at 05:47
  • Update: After a few changes to the `wxs` file, the removal of the install directory from the environment variable stopped working. I am not sure if this is because the installer produced is buggy or I made some mistake. – user3613932 Jul 25 '18 at 07:27
23

Another thing to note is, Environment need to be placed inside a component with directory, e.g.

<DirectoryRef Id="TARGETDIR">
  <Component Id="Path" Guid="{xxx-xxx-xxx-xxx}">
    <Environment Id="PATH" Name="PATH" Value="[INSTALLDIR]" Permanent="no" Part="last" Action="set" System="no" />
  </Component>
</DirectoryRef>

Details of Wix Element described at Environment Element

Deqing
  • 14,098
  • 15
  • 84
  • 131
  • 1
    actually just needs to be in a fragment then component, no need for a directoryref – Nathan Boyd Aug 15 '12 at 15:18
  • 1
    I'm trying to set env variable using this answer but without success: I can't find right place for `DirectoryRef`. I also tried to place `Component` without `DirectoryRef` parent. Could somebody suggest where should I place `Environment` tag in my wxs file: https://gist.github.com/pyeremenko/891eceb779197e4be240 – Peter Yeremenko May 18 '15 at 07:45
  • I ended up putting `Component` (without `DirectoryRef`) right under the root level `Directory`, i.e., `` and it worked fine for me. – hyong Aug 02 '19 at 22:13
2

Had the same exact problem, this have worked for me:

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="DataBaseds_Service_Installer" />
    </Directory>
</Directory>

<ComponentGroup Id="Components" Directory="INSTALLFOLDER">
 
  ...some components  
</ComponentGroup>

<DirectoryRef Id="TARGETDIR">
  <Component Id="MYSQL_PASSWORD" Guid="..."
    <Environment Id=HERE YOU CAN ADD THIS  :)/>
  </Component>      
</DirectoryRef>
FortyTwo
  • 2,414
  • 3
  • 22
  • 33
karollo
  • 573
  • 8
  • 22