【问题标题】:Running Powershell script in WiX install as an Administrator以管理员身份在 WiX 安装中运行 Powershell 脚本
【发布时间】:2018-01-10 19:39:14
【问题描述】:

我有一个 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 失败并出现以下错误:

脚本“Start.ps1”无法运行,因为它包含以管理员身份运行的“#requires”语句。当前的 Windows PowerShell 会话未以管理员身份运行。使用“以管理员身份运行”选项启动 Windows PowerShell,然后再次尝试运行该脚本。

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

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

【问题讨论】:

    标签: windows powershell wix


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-24
      • 2018-07-29
      • 2015-04-17
      • 1970-01-01
      • 2011-09-01
      • 2016-11-22
      • 2015-01-22
      • 2017-05-27
      相关资源
      最近更新 更多