简体   繁体   中英

Wix - change the installation folder based on privilege

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?

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>

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>

将属性ALLUSERS设置为2.另请参见单个包创作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM