Aleph0
Aleph0

Reputation: 6084

Set default installation directory depending on rights

I'm trying to use Wix# to build an MSI installer and I'm quite satisfied with the easy-to-use syntax compared to Wix.

Now, I'm trying to do something off-standard and I'm a bit lost, as I'm not really acquainted with Wix.

Basically, I wanted to set the default target installation directory depending if the installer was called with admin rights or being installed by a default user.

Being a normal user I want to set the default installation directory to %LocalAppData%\MyProduct, whereas as an admin the default installation directory should be %ProgramFiles%.

Using plain Wix there seems to be an solution, that is managable.

How, can this be accomplished by using Wix#?

I have to mention, that I'm really laking the skills to do so alone, as I neither really know WiX, Msi and even C# in any kind of depths. Hence, I'm looking for a minimal, reproducible solution of my problem.

Upvotes: 4

Views: 375

Answers (1)

Jeremy Thompson
Jeremy Thompson

Reputation: 65702

In the example you linked (by the author of WiX) it shows how to set the directory depending if per user or per machine:

<DirectoryRef Id="TARGETDIR">
    <Directory Id="ApplicationFolder" Name="App" />
</DirectoryRef>

If its an Admin install its Per-Machine, if its non-admin the default is Per User:

<CustomAction Id="PerMachineInstall" Property="ApplicationFolder" Value="[ProgramFilesFolder]\[ApplicationFolderName]" Execute="immediate" />
<CustomAction Id="PerUserInstall" Property="ApplicationFolder" Value="[LocalAppDataFolder]\Apps\[ApplicationFolderName]" Execute="immediate" />

You should be able to change [LocalAppDataFolder]\Apps\[ApplicationFolderName] to [LocalAppData]\MyProduct

The problem with the code is that the <Directory Id="ApplicationFolder" is lower case.

As per https://wixtoolset.org/documentation/manual/v3/xsd/wix/setdirectory.html

The directory ID must be all uppercase characters because it must be passed from the UI to the execute sequence to take effect.

Related: Wix - Setting Install Folder correctly

Upvotes: 4

Related Questions