我有一个 WiX 安装程序,需要在安装后运行 Powershell 脚本。我已经到了安装程序实际上运行脚本的地步:
<SetProperty Id="RunStartScript"
Before ="RunStartScript"
Sequence="execute"
Value=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File "[INSTALLDIR]Scripts/Start.ps1"" />
<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/