wix - 在 Wix 安装程序中以管理员模式在 customAction 中运行 ExeCommand

标签 wix installation impersonation wix3.7 elevated-privileges

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

我用谷歌搜索并找到了关键字 提升特权和冒充 可能会帮助我。

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

正如您在上面看到的,我使用了设置为 perMachine 的 InstallScope 属性,并且在 CustomAction 元素中使用了 Impersonate="No":
 <CustomAction Id='comReg' Directory='INSTALLLOCATION'  Impersonate='no'  
  ExeCommand='"[NETFRAMEWORK40CLIENTINSTALLROOTDIR]regasm.exe" "[INSTALLLOCATION]myProduct.dll"  /codebase' Return='check' />

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

任何人都可以告诉我这些关键字“ 提升特权和冒充”
<InstallExecuteSequence>
  <Custom Action='comReg' After='InstallFinalize'>NOT REMOVE</Custom>
  <Custom Action='comUnreg' Before='RemoveFiles'>REMOVE</Custom>
</InstallExecuteSequence>

怎么做?

最佳答案

wix documentation here解释 Impersonate 属性:

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 属性:

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.



目前您的自定义操作是即时的,这意味着它以用户权限运行。见 this blog post很多细节,但特别是:

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.



您永远不应该通过立即自定义操作来修改机器状态。使用延迟的,并保持模拟为否,它应该可以工作:
<CustomAction Id='comReg' Directory='INSTALLLOCATION' Execute='deferred' Impersonate='no' ExeCommand='"[NETFRAMEWORK40CLIENTINSTALLROOTDIR]regasm.exe" "[INSTALLLOCATION]EAWordImporter.dll" /codebase' Return='check' />

编辑 :使用 InstallExecuteSequence 元素安排自定义操作:
<InstallExecuteSequence>
    <Custom Action='comReg' Before='InstallFinalize'/>
</InstallExecuteSequence>

关于wix - 在 Wix 安装程序中以管理员模式在 customAction 中运行 ExeCommand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24484478/

相关文章:

mysql - Wordpress v2.9.2 无法在 MAMP 上创建数据库

asp.net - 临时授予 ASP.NET 代码提升的管理员权限

c# - WindowsIdentity.Impersonate() 混淆

visual-studio - 将 Wix 项目迁移到 4.0 版

visual-studio-2010 - WiX 库项目不适合共享组件定义(并且没有办法参数化 Guid),我说得对吗?

wix - 使用 WiX 的“刻录”和自定义 MBA - 在 NetFx45Web 包上修复失败

installation - 如何在wix安装程序中添加复选框

mysql - PHPMyAdmin 配置由于 MySQL 用户密码而不起作用?

python - 如何使用 Python 2.7 安装 aggdraw

powershell - 使用Invoke-WmiMethod以特定用户的身份在远程计算机上运行可执行文件