Wix - 根据权限更改安装文件夹

时间:2009-06-19 10:21:52

标签: wix wix3

我必须使用Wix创建一个安装包。如果管理员用户正在安装该程序包,则应将其安装到%programfiles%/ [applicationName]中,如果该用户是非管理员用户,则应将其安装到其本地配置文件文件夹(LocalAppDataFolder)中。

怎么可能?

4 个答案:

答案 0 :(得分:4)

很久以前我为ClickThrough写了这个。解决方案看起来很像这样(你提供了一个名为“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>

答案 1 :(得分:2)

覆盖ProgramFilesFolder属性如下:

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

<Directory Id="ProgramFilesFolder" Name="PFiles">
    <Directory Id="INSTALLDIR" Name="My Folder">
        ...
    </Directory>
</Directory>

答案 2 :(得分:0)

你的代码无法在我的wix项目上运行 目前我使用AdminUser =“1”来判断我们是否处于管理员权限

答案 3 :(得分:0)

将属性ALLUSERS设置为2.另请参阅Single Package Authoring