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

查看:168
本文介绍了在Wix Installer中以管理员模式在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.

我已经在Google上搜索了,发现关键字特权提升和冒充可能对我有帮助.

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.

还有谁能告诉我这些关键字"特权提升和模拟"

And can anyone please tell me about these keywords "Elevated Privileges & impersonate"

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

该怎么做?

推荐答案

此处的Wix文档解释模拟"属性:

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

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.

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

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' />

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

EDIT: Schedule the custom action using the InstallExecuteSequence element:

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

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

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