Get an environment variable into a WIX property

Edward picture Edward · Aug 11, 2010 · Viewed 28.3k times · Source

Is there a way to get an environment variable in WIX into a property?

I'm trying to get the USERPROFILE with:

Property Id="UserFolder"  Value="$(env.USERPROFILE)\EdwardsApp\MyFolder"

But this only picks up the USERPROFILE of the build machine, where the installer is built.

I want it to use the USERPROFILE of the machine where the app is being installed.

Answer

demp picture demp · Apr 24, 2012

Alternative is to use SetProperty element - it will effectively create type 51 custom Action. It is simpler than using Custom Action as you don't need to separately specify the schedule for it - everything is done in one element. In my example below, I set the property only if its empty, i.e. was not passed from the command line.

Example:

<SetProperty Id="PROP_MYSOME"
             Before="InstallInitialize" 
             Sequence="execute"
             Value="[%USERDOMAIN]">
    <![CDATA[NOT Installed AND PROP_MYSOME=""]]>
</SetProperty>