Windows 以管理员身份在WiX安装中运行Powershell脚本
我有一个WiX安装程序,需要在安装后运行Powershell脚本。我已经到了安装程序实际运行脚本时使用以下内容的地步:Windows 以管理员身份在WiX安装中运行Powershell脚本,windows,powershell,wix,Windows,Powershell,Wix,我有一个WiX安装程序,需要在安装后运行Powershell脚本。我已经到了安装程序实际运行脚本时使用以下内容的地步: <SetProperty Id="RunStartScript" Before ="RunStartScript" Sequence="execute" Value=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -
<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>
未安装或升级ProductCode
但是,msi因以下错误而失败:
无法运行脚本“Start.ps1”,因为它包含以管理员身份运行的“#requires”语句。当前Windows PowerShell会话未以管理员身份运行。使用“以管理员身份运行”选项启动Windows PowerShell,然后再次尝试运行该脚本
安装程序在安装开始之前已经提示输入管理员,因此我假设PowerShell命令已经以管理员身份运行,但情况肯定不是这样
我找到了一些答案,包括在脚本开头添加代码,以检查管理员权限,并将命令和参数传递给管理员会话,但是我正在寻找另一个选项的可能性,因为这是一个别人提供的签名脚本,所以对它的任何更改都必须返回给他们重新签名。需要将
Impersonate=“yes”
更改为Impersonate=“no”
,这样Powershell会话就不会以普通用户的身份运行