如何使用提升权限运行自定义可执行文件

use*_*528 15 windows-installer wix

我需要在安装之后和卸载之前运行可执行文件以进行自定义安装/拆除.它需要以提升的权限运行.怎么做到这一点?

Che*_*rra 18

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

另一个链接真正解释了所有类型的自定义操作.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.
Run Code Online (Sandbox Code Playgroud)

自定义操作的入口点接收安装会话的句柄.在执行延迟的自定义操作期间,会话可能不再存在.要获取属性的值,请使用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>
Run Code Online (Sandbox Code Playgroud)

首先,我们将MyCA.exe添加到File表中.

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

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

这应该可以帮助您排除缺失的内容,但我强烈建议您查看所有类型的自定义操作,以便在以后制作更多安装程序时帮助您

  • @Yan Sklyarenko,它没有.这是真实答案的10%. (2认同)

use*_*528 14

所以,最终的解决方案是这样的:

<CustomAction Id="Install" Directory="APPLICATIONROOTDIRECTORY"
              Execute="deferred" Impersonate="no" Return="ignore"
              ExeCommand="[APPLICATIONROOTDIRECTORY]MyExeName.exe -install" />

<CustomAction Id="Uninstall" Directory="APPLICATIONROOTDIRECTORY"
              Execute="deferred" Impersonate="no" Return="ignore"
              ExeCommand="[APPLICATIONROOTDIRECTORY]MyExeName.exe -uninstall" />

<InstallExecuteSequence>

  <Custom Action='Install' After='InstallFiles' >
    $ProductComponent = 3
  </Custom>

  <Custom Action='Uninstall' After='InstallInitialize' >
    ?ProductComponent = 3
  </Custom>

</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)

有什么建议来改善吗?


jac*_*ous 5

您可以为安装和修复序列添加"NOT REMOVE".并且'仅对UnInstall序列安装AND(REMOVE ="ALL")'.

    <InstallExecuteSequence>
      <Custom Action='Install' After='InstallFiles' >
        NOT REMOVE
      </Custom>

      <Custom Action='Uninstall' After='InstallFiles' >
         Installed AND (REMOVE = "ALL")
      </Custom>

    </InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)