在 Wix 安装程序中以管理员模式在 customAction 中运行 ExeCommand [英] Run ExeCommand in customAction as Administrator mode in Wix Installer

查看:32
本文介绍了在 Wix 安装程序中以管理员模式在 customAction 中运行 ExeCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 wix 安装程序的新手.我已经使用 wix 安装程序为我的应用程序开发了一个设置,我需要执行自定义操作以在 cmd.exe 中运行命令.在 XP 中它工作正常.但在 Windows 8 &7 cmd提示符需要以管理员身份运行.

I am new to wix installer. I have developed a set-up using wix installer for my application and I need to execute a Custom Action to run a command in cmd.exe. In XP it works fine. But in Windows 8 & 7 the cmd prompt needs to be run as administrator.

我在谷歌上搜索并发现关键字提升特权和冒充可能对我有帮助.

I have googled and found the keywords Elevated Privileges and impersonate might help me.

<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"   InstallPrivileges="elevated"></Package>

如上所示,我使用了设置为 perMachine 的 InstallScope 属性,并且在 CustomAction 元素中使用了 Impersonate="No":

As you can see above, I used the InstallScope attribute set to perMachine, and I have used Impersonate="No" in the CustomAction element:

 <CustomAction Id='comReg' Directory='INSTALLLOCATION'  Impersonate='no'  
  ExeCommand='"[NETFRAMEWORK40CLIENTINSTALLROOTDIR]regasm.exe" "[INSTALLLOCATION]myProduct.dll"  /codebase' Return='check' />

但是我在安装时没有得到任何更改.我需要命令提示符才能在管理员模式下打开并运行上述命令.

But I didn't get any changes while installating. I need the command prompt to open and run the above command in Administrator Mode.

谁能告诉我这些关键字提升特权和冒充"

<InstallExecuteSequence>
  <Custom Action='comReg' After='InstallFinalize'>NOT REMOVE</Custom>
  <Custom Action='comUnreg' Before='RemoveFiles'>REMOVE</Custom>
</InstallExecuteSequence>

怎么做?

推荐答案

这里的 wix 文档 解释了 Impersonate 属性:

The wix documentation here explains the Impersonate attribute:

此属性指定在执行此自定义操作时,作为 LocalSystem 执行的 Windows 安装程序是否应模拟安装用户的用户上下文.通常,该值应为yes",除非自定义操作需要提升权限才能将更改应用于计算机.

This attribute specifies whether the Windows Installer, which executes as LocalSystem, should impersonate the user context of the installing user when executing this custom action. Typically the value should be 'yes', except when the custom action needs elevated privileges to apply changes to the machine.

您还需要了解延迟自定义操作和立即自定义操作之间的区别.请参阅同一帮助页面上的 Execute 属性:

You also need to understand the difference between deferred and immediate custom actions. See the Execute attribute on the same help page:

该属性指示自定义操作的调度.此属性的值必须是以下之一:

This attribute indicates the scheduling of the custom action. This attribute's value must be one of the following:

延期指示自定义操作在脚本中运行(可能具有提升的权限).立即表示自定义操作将在正常处理时间内以用户权限运行.这是默认设置.

deferred Indicates that the custom action runs in-script (possibly with elevated privileges). immediate Indicates that the custom action will run during normal processing time with user privileges. This is the default.

目前您的自定义操作是即时的,这意味着它以用户权限运行.请参阅这篇博文了解更多信息细节,但特别是:

At present your custom action is immediate, which means it is running with user privileges. See this blog post for lots of details, but particularly:

任何即时自定义操作都会冒充调用用户.在 Windows Vista 之前,这不是问题,因为此时安装管理用户拥有特权令牌.随着 Windows Vista 中 UAC 的引入,启用了 UAC 的默认管理令牌是一个过滤令牌,并不拥有所有权限.由于立即自定义操作不应该修改机器状态 - 只是为了收集状态数据并安排自定义操作推迟运行 - 这仍然不应该是一个问题.毕竟,此时应该进行安装和回滚脚本的生成.

Any immediate custom actions impersonate the invoking user. Before Windows Vista this wasn't a problem since at this point the installing administrative user had a privileged token. With the introduction of UAC in Windows Vista the default administrative token with UAC enabled is a filtered token and does not hold all privileges. Since immediate custom actions are not supposed to modify machine state - only to gather state data and schedule custom actions to run deferred - this still shouldn't be a problem. After all, at this point the generation of the installation and rollback scripts is all that should be going on.

您不应该立即通过自定义操作来修改机器状态.使用延迟的,并保持模拟为否,它应该可以工作:

You should never modify machine state with an immediate custom action. Use a deferred one, and keep impersonate to no, and it should work:

<CustomAction Id='comReg' Directory='INSTALLLOCATION' Execute='deferred' Impersonate='no' ExeCommand='"[NETFRAMEWORK40CLIENTINSTALLROOTDIR]regasm.exe" "[INSTALLLOCATION]EAWordImporter.dll" /codebase' Return='check' />

EDIT:使用 InstallExecuteSequence 元素安排自定义操作:

EDIT: Schedule the custom action using the InstallExecuteSequence element:

<InstallExecuteSequence>
    <Custom Action='comReg' Before='InstallFinalize'/>
</InstallExecuteSequence>

这篇关于在 Wix 安装程序中以管理员模式在 customAction 中运行 ExeCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆