在安装后和卸载之前,我需要运行可执行文件以进行自定义设置/拆卸。它需要以提升的特权运行。如何正确做到这一点?

最佳答案

在如何编写需要管理特权的自定义操作一节中查看此blog

另一个link确实解释了自定义操作的所有类型。
Wix中的CustomAction元素。

这应该可以为您提供更多帮助。

在查看您的解决方案之后,您似乎正在执行Type 18 CustomAction,在这里我为这些类型粘贴了先前Blog的内容:

自定义操作类型18
调用在当前会话期间与应用程序一起安装的可执行文件。
CustomAction表中的Source列包含File表中记录的键。

CustomAction表中的Target列包含可执行文件的命令行字符串。
所有返回处理,执行计划和脚本内执行选项均适用。

由于文件是随应用程序一起安装的,因此对自定义操作类型18有顺序限制:

If the source file is not already installed on the computer:
    Custom action must be sequenced after CostFinalize action because only after this action path to the file can be resolved.
If the source file is not already installed on the computer:
    Deferred custom actions of this type must be sequenced after the InstallFiles action.
    Non-deferred custom actions of this type must be sequenced after the InstallFinalize action.


定制操作的入口点将接收安装会话的句柄。在执行延迟的自定义操作期间,会话可能不再存在。要获取属性的值,请使用CustomActionData属性。

以下是在Wix中添加Type 18自定义操作的方法:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Component Id="Component1"
             Guid="*">
    <File Id="MyCA" Name="MyCA.exe" />
  </Component>
</Directory>

<CustomAction Id="DoSomething"
              FileKey="MyCA"
              ExeCommand="-switch"
              Execute="deferred"
              Return="check"
              HideTarget="no"
              Impersonate="no" />

<InstallExecuteSequence>
  <Custom Action="DoSomething" Before="InstallFinalize" />
</InstallExecuteSequence>


首先,我们将MyCA.exe添加到“文件”表中。

我们还将类型18的自定义操作添加到CustomAction表中。 FileKey属性指向具有自定义操作dll的元素。 ExeCommand属性指定可执行文件的命令行字符串。

最后要做的是在所有必需的序列表中安排我们的自定义操作。

这应该可以帮助您解决丢失的内容,但是我强烈建议您查看所有自定义操作类型,这些类型以后将在您安装更多安装程序时为您提供帮助

07-24 09:48
查看更多