Laurent Mesguen
Laurent Mesguen

Reputation: 394

%USERPROFILE does not work with WiX

I am making a setup of my application with WiX. I want to copy/paste an .ini file in the current user folder on Windows (C:\Users\{username})

I saw on this post that I should use the tag [%USERPROFILE]. I use it this way :

<Directory Id="UserFolder" Name="[%USERPROFILE]">
<Directory/>

As a result, a folder [%USERPROFILE] is created in C:\ containing the .ini file. This is not what I want.

Does anyone have an idea how to make it work ?

Upvotes: 0

Views: 1633

Answers (1)

Michael Urman
Michael Urman

Reputation: 15905

[%USERPROFILE] is a valid environment variable reference, but I don't think it can be used in this context, as this context isn't formatted. See the Directory Table for details.

Note that, as mentioned in the comments, %USERPROFILE% is likely the wrong place for any files you may want to install. Consider using another predefined folder, such as AppDataFolder, LocalAppDataFolder, or PersonalFolder.

If you go with PersonalFolder, I believe you can just use that instead:

<Directory Id="PersonalFolder"> ... </Directory>

If there is no satisfactory predefined folder property, you can use either a type 51 or a type 35 custom action (depending on whether you schedule it before or after CostFinalize to set the run time value of your folder to [%USERPROFILE]. Those custom actions will format the value they use. Make sure to use an ALL-CAPS name so that it can be set at run time. For example, if the directory is called USERPROFILEFOLDER:

<SetDirectory Id="USERPROFILEFOLDER" Value="[%USERPROFILE]"/>
<!-- or -->
<SetProperty Id="USERPROFILEFOLDER" Value="[%USERPROFILE]"/>

(And don't forget to schedule the action somewhere.)

Upvotes: 2

Related Questions