0

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 ?

Community
  • 1
  • 1
Laurent Mesguen
  • 354
  • 2
  • 6
  • 22
  • http://stackoverflow.com/questions/17500373/wix-toolset-setting-a-property-to-user-profile-folder-path-and-program-files and http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Environment-variables-into-a-WIX-property-td5412818.html might be of interest to you. I've never seen [%USERPROFILE], and it looks weird. Cursory check doesn't find it in the Wix docs. Might not be valid anymore. –  Jan 20 '17 at 15:42
  • 1
    Thanks for your inputs @Will I have tried what they mentionned, in vain. – Laurent Mesguen Jan 20 '17 at 16:47
  • Any reference to the current user won't be meaningful for per-machine installs. Are you sure your setup is per-user rather than per-machine? (And in any case, putting your .ini file directly into the user profile rather than the user's application data folder is the wrong thing to do. Windows isn't Linux!) – Harry Johnston Jan 20 '17 at 22:27
  • I need the setup to be per-machine. But this file has to be copied in the USER folder because it stores the session data, another user may have different settings. – Laurent Mesguen Jan 23 '17 at 10:14

1 Answers1

2

[%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.)

Michael Urman
  • 15,737
  • 2
  • 28
  • 44