1

Brand new to WiX and I'm trying to fix a bug in some software I took over recently. As part of the product definition we have certain files being installed to the user's "AppData\Local" directory. The current project setup works fine when the user has install privileges, with the files being placed in the expected users "AppData\Local" directory.

However, if the UAC prompt pops up requiring admin credentials, the files end up being install in the admin account's "AppData\Local" directory instead.

In the product file we have something like:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="LocalAppDataFolder">
    <Directory Id="MyData" Name="My Data">
      ...
    </Directory>
  </Directory>
</Directory>

And then in a heat.exe generated file I have

<Fragment>
  <DirectoryRef Id="MyData">
    <Directory Id="UserMaps" Name="User Maps" />
  </DirectoryRef>
</Fragment>
<Fragment>
  <ComponentGroup Id="User_Maps_Components">
    <Component Id="Map1.png" Directory="UserMaps" Guid="{C27...autogenerated}">
      <File Id="Map1.png" Source="$(var.MapPath)\Map1.png" KeyPath="no" />
      <RegistryValue KeyPath="yes" Root="HKCU" Key="Software\MyApp\Usermaps" Type="integer" Value="1" Name="Map1.png" />
    </Component>
  </ComponentGroup>
</Fragment>

Is there a way to ensure that the files will be installed to the initiating user's directories, rather than the admin's account?

We have files installing to "Program Files" as well, so I could always install the files there and copy them over as part of my applications initialization logic if they aren't found in the active user's folders, but was interested in seeing if there was a WiX specific way of doing things.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
BiggPlanet
  • 77
  • 1
  • 12
  • 2
    Installation of per-user data doesn't work well with WiX or Windows Installer in general. To support more than the one user that runs the installation, you have to create an advertised shortcut so the repair runs for other users and installs the missing per-user data. Advertised shortcuts have their own issues and often tend to invoke the repair even when there isn't really anything "broken", creating a nuisance for the user. Best practice is to let the application handle per-user data. – zett42 Jul 25 '18 at 21:31

1 Answers1

2

I assume you are actually entering an admin password and specifying an admin account to run the setup with? That is as opposed to elevating the admin account you are logged in with. The latter should make the file install in the expected folder. The former would install like you describe.

I would roll with the approach you describe yourself: copy the file in place to each user profile from a copy installed per machine. I wrote up some suggestions for user profile and HKCU deployment a while back. Just some thoughts on the subject - a subject which seems to have few good answers. The Active Setup approach is apparently no longer supported in Windows 10.


Throwing in Some Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • First, thanks for linking to the other SO posts, I hate posting dup questions but my Google magic failed me this time. I was afraid that copying would be my only choice. In this scenario, does that mean there is no way to clean up files copied to individual user's directories? – BiggPlanet Jul 26 '18 at 13:35
  • 1
    Once files make it into the user profile, they are technically user data, and user data should not be uninstalled or meddled with in my opinion. If you want to install files shared for all users, you could install to %ProgramData% instead. That should map to the [CommonAppDataFolder property](https://learn.microsoft.com/en-us/windows/desktop/msi/commonappdatafolder) in MSI (so many redirects and redefinitions in different operating systems). Then there is only one instance of the files, and you can clean out everything on uninstall. – Stein Åsmul Jul 26 '18 at 14:00
  • 1
    I have wondered whether it is possible to hook up to Microsoft's [`Cleanmgr.exe`](https://support.microsoft.com/en-us/help/253597/automating-disk-cleanup-tool-in-windows) (launch by holding down `Windows Key`, tap `R` and type `Cleanmgr.exe` and press `Enter`) to allow cleanup as a sort of "garbage collection" feature, but I have never gotten around to looking at it. I'd say it is better to just document in a support article how to clean out the remaining user data - if desired. – Stein Åsmul Jul 26 '18 at 14:01
  • The documentation approach is probably best for my case, as each user will need their distinct copy of the files, since they can make independent changes to them. Thanks for you help! – BiggPlanet Jul 26 '18 at 14:24
  • No problem, glad it made sense to you. If you run into cases where pre-existing user data (in HKCU or in the user profile) has inconsistencies that need to be resolved for your application to function correctly (binary streams for saved toolbar customizations that suddenly crash your app on launch - for example), there is a way you can check here: http://forum.installsite.net/index.php?showtopic=21552. You can use the application launch sequence to do any "data cleaning" per-user when you absolutely have to (and make sure the cleanup runs only once). – Stein Åsmul Jul 26 '18 at 14:28
  • Resurrected link to forum (above broken link): [HKCU or HKLM - Where should a setup install registry data](https://web.archive.org/web/20160313224750/http://forum.installsite.net/index.php?showtopic=21552). – Stein Åsmul Mar 04 '19 at 22:13