28

I need to install a file into the Environment.SpecialFolder.ApplicationData folder, which differs between XP and Vista. Is there a built in way to reference the correct folder in WiX or will I have to use conditional checks for OS and do it manually?

If I have to do the latter, how do I reference the current windows user's directory in Vista?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Davy8
  • 30,868
  • 25
  • 115
  • 173

1 Answers1

52

Use Directory element with Id set to AppDataFolder:

<Directory Id="AppDataFolder">
  <Directory Id="MyAppFolder" Name="My">
    <Component Id="MyComponent">
      <File Source="Files\test1.txt" />
    </Component>
  </Directory>
</Directory>

This will result in test1.txt being installed to C:\Users\username\AppData\Roaming\My on Windows 7 and to C:\Documents and Settings\username\Application Data\My on Windows XP.

MSDN has a list of properties that you can use to reference special folders.

Pavel Chuchuva
  • 22,633
  • 10
  • 99
  • 115
  • 3
    Note that the `Name="AppDataFolder"` attribute can be omitted here. Only the Id attribute is required there. Also, you can omit the component `Guid`; wix will now generate a stable Guid automatically. Finally, you can omit the `Id`, `Name` and `KeyPath` attributes on the `File` element. The `Id` and `Name` will have those values by default based on the `Source`, and the file will automatically be the keypath of the component because the component doesn't contain anything else. – Wim Coenen Apr 25 '14 at 08:08
  • 5
    Unfortunately, you get an _"error LGHT0204 : ICE38: Component MyComponent installs to user profile. It must use a registry key under HKCU as its KeyPath, not a file."_, so you have to add a RegistryValue as the KeyPath of the component. I wish I could get away with just the file. – TechAurelian May 13 '16 at 07:39