Wix - change the installation folder based on privilege
Asked Answered
F

3

7

I have to create an installation package using Wix. If an admin user is installing the package, it should install into %programfiles%/[applicationName], if the user is an non-admin user then it should install into its local profile folder( LocalAppDataFolder).

How it is possible?

Fuentes answered 19/6, 2009 at 10:21 Comment(0)
M
5

I wrote this for ClickThrough a long time ago. Solution from that looks a lot like this (You provide a Property called "ApplicationFolderName"):

    <Property Id="A" Secure="yes" />

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

    <Condition Message="Must specify TARGETDIR property when doing an administrative install.">Installed OR (ACTION="ADMIN" AND TARGETDIR&lt;&gt;"")</Condition>

    <CustomAction Id="TARGETDIRtoA" Property="A" Value="[TARGETDIR]" Execute="firstSequence" />

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

    <InstallUISequence>
        <Custom Action="SpecifiedA" Before="LaunchConditions">NOT Installed</Custom>
    </InstallUISequence>

    <InstallExecuteSequence>
        <Custom Action="PerMachineInstall" Before="CostFinalize">NOT Installed AND ACTION="INSTALL" AND A="" AND (ALLUSERS=1 OR (ALLUSERS=2 AND Privileged))</Custom>
        <Custom Action="PerUserInstall" Before="CostFinalize">NOT Installed AND ACTION="INSTALL" AND A="" AND (ALLUSERS="" OR (ALLUSERS=2 AND (NOT Privileged))</Custom>
    </InstallExecuteSequence>
Misunderstanding answered 19/6, 2009 at 19:11 Comment(0)
S
3

Overriding ProgramFilesFolder property as following should work:

<SetProperty Id="ProgramFilesFolder" Value="[AppDataFolder]" Before="CostFinalize"><![CDATA[ NOT Privileged]]></SetProperty>

<Directory Id="ProgramFilesFolder" Name="PFiles">
    <Directory Id="INSTALLDIR" Name="My Folder">
        ...
    </Directory>
</Directory>
Stinger answered 30/6, 2011 at 9:33 Comment(1)
I used this to create a 64 bit installer that could install all it's things into Program Files (x86) based on a condition in the SetProperty element that does the overriding like this: <SetProperty Id="ProgramFiles64Folder" Value="[ProgramFilesFolder]" Before="CostInitialize">Earleanearleen
M
0

Set property ALLUSERS to 2. See also Single Package Authoring.

Mackinaw answered 20/12, 2011 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.