Can anyone give me a example of modifying windows environment system variables in WIX?
Asked Answered
S

4

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!

Shepherd answered 19/12, 2009 at 1:12 Comment(0)
B
56

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].

Brede answered 19/12, 2009 at 1:34 Comment(7)
Setting Permanent="no" will remove the appended part (but not the entire value) on uninstall.Aquarist
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!)Caz
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.Meiny
Wix Official Documentation Basic and Wix Official Documentation Detailed for Environment tag.Copacetic
@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?Copacetic
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.Copacetic
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.Copacetic
C
24

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

Cretonne answered 6/7, 2012 at 6:22 Comment(3)
actually just needs to be in a fragment then component, no need for a directoryrefBeckner
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: gist.github.com/pyeremenko/891eceb779197e4be240Sugared
I ended up putting Component (without DirectoryRef) right under the root level Directory, i.e., <Directory Id="TARGETDIR" Name="SourceDir"> and it worked fine for me.Scopula
A
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>
Adlare answered 22/9, 2017 at 13:44 Comment(0)
L
0

This code is working for me:

<ComponentGroup Id="ProductComponents" >
  <Component Id="Path" Directory="INSTALLFOLDER" Guid="1014136b-a934-47db-bf69-5da949b2528b">
    <CreateFolder/>
    <Environment Id="PATH" Name="PATH" Value="[INSTALLFOLDER]" Permanent="no" Part="last" Action="set" System="no" />
  </Component>
</ComponentGroup>
Lubber answered 5/9, 2023 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.