一直在尝试为我的最新项目创建一个 WiX 安装程序。我有一个奇怪的问题,如果我通过 cmd 提示符以管理员身份运行 msi,它工作正常,自定义操作会毫不费力地启动,一切正常,但如果我双击 msi,自定义操作将不起作用并且安装程序失败。我使用的是 Visual Studio 2012 和 Windows 7。
<!--Custom Actions-->
<Binary Id='customShortcut' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/>
<Binary Id='customDir' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/>
<Binary Id='removeDir' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/>
<CustomAction Id='customShortcutId' BinaryKey='customShortcut' DllEntry='CustomShortcut'
Execute='immediate' Impersonate='no' Return='check' />
<CustomAction Id='customDirId' BinaryKey='customDir' DllEntry='CustomDir'
Execute='immediate' Impersonate='no' Return='check'/>
<CustomAction Id='removeDirId' BinaryKey='removeDir' DllEntry='RemoveDir'
Execute='immediate' Impersonate='no' Return='check'/>
<InstallExecuteSequence>
<Custom Action='customDirId' Before='InstallFinalize'/>
<Custom Action='customShortcutId' After='InstallFinalize'/>
<Custom Action="removeDirId" After="InstallValidate">REMOVE="ALL"</Custom>
</InstallExecuteSequence>
最佳答案
安装的提升部分不会执行'immediate'
自定义操作。因此,它们仅在安装过程中运行提升(如您所见)。要提升自定义操作,它们必须是事务脚本的一部分。为此,请设置 CustomAction
元素 Execute='deferred'
属性。
注意:延迟的自定义操作具有 MSI SDK 中记录的其他限制:'Deferred Execution Custom Actions' topic 。由于自定义操作看起来正在修改计算机状态,因此您还需要考虑添加回滚自定义操作以撤消延迟自定义操作所做的更改。
写好自定义操作非常具有挑战性。这就是为什么自定义操作是导致安装失败的最大原因的部分原因。如果您可以避免编写自定义操作,我强烈建议您这样做。 :)
关于windows-7 - WiX msi 自定义操作无法在 Windows 7 上以有限权限运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15893627/