windows - 以管理员身份在 WiX 安装中运行 Powershell 脚本

标签 windows powershell wix

我有一个 WiX 安装程序,需要在安装后运行 Powershell 脚本。我已经到了安装程序实际上运行脚本的地步:

<SetProperty Id="RunStartScript"
        Before ="RunStartScript"
        Sequence="execute"
        Value="&quot;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe&quot; -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File &quot;[INSTALLDIR]Scripts/Start.ps1&quot;" />

<CustomAction Id="RunStartScript" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="check" Impersonate="yes" />
<InstallExecuteSequence>
      <Custom Action="RunStartScript" Before="InstallFinalize">NOT Installed OR UPGRADINGPRODUCTCODE</Custom>
</InstallExecuteSequence>

但是,msi 失败并出现此错误:

The script 'Start.ps1' cannot be run because it contains a "#requires" statement for running as Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by using the Run as Administrator option, and then try running the script again.

安装程序在安装开始前已经提示需要管理员身份,因此我假设 PowerShell 命令已经以管理员身份运行,但事实并非如此。

我找到了一些答案,涉及将代码添加到脚本的开头以检查管理员权限并将命令和参数传递给管理员 session ,但我正在寻找另一种选择的可能性,因为这是其他人提供的签名脚本,因此对其进行的任何更改都必须返回给他们重新签名。

最佳答案

需要将 Impersonate="yes" 更改为 Impersonate="no" 以便 Powershell session 不会以普通用户身份运行。

关于windows - 以管理员身份在 WiX 安装中运行 Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48194882/

相关文章:

wix - 是否可以更改我的 WIX 安装成功对话框中的消息

windows - 现在的程序员应该具备哪些技能?

python - 从另一个进程正在使用的文件中读取

sql-server - 调用-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server

powershell - PowerShell:导入CSV文件,计数组大小和输出到原始文件,并在计数后添加新列

wix - 使用Windows-Installer了解GUIDS,更新和补丁

windows - 如何将新项目添加到某些文件扩展名上下文菜单

windows - Windows 上的 Memcached 无法忽略 SIGHUP : No error failed to daemon() in order to daemonize

java - 通过 powershell 启动 selenium grid hub 时出错 - VSTS/TFS

WiX 安装程序会在卸载时删除文件,但不会在升级时删除文件