从 WiX 安装程序运行 PowerShell 脚本 [英] Run PowerShell script from WiX installer

查看:47
本文介绍了从 WiX 安装程序运行 PowerShell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了几个示例,展示了如何从 WiX 运行 PowerShell 脚本,但没有成功运行其中任何一个.所以,我想发布我所拥有的,希望有人能指出我做错了什么.

I have found a couple of examples showing how to run a PowerShell script from WiX but have not been successful running either of them. So, I'd like to post what I have with the hope that someone can point out what I am doing wrong.

<!--Install the PowerShell script-->
<DirectoryRef Id="INSTALLFOLDER">
  <Component Id="cmp_ShutdownIExplore" Guid="{4AFAACBC-97BB-416f-9946-68E2A795EA20}" KeyPath="yes">
    <File Id="ShutdownIExplore" Name="ShutdownIExplore.ps1" Source="$(var.ProjectDir)Source\PowerShell\ShutdownIExplore.ps1" Vital="yes" />
  </Component>
</DirectoryRef>

<!--Define the CustomAction for running the PowerShell script-->
<CustomAction Id="RunPowerShellScript" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="yes" />

<InstallExecuteSequence>

  <!--Invoke PowerShell script -->
  <Custom Action="RunPowerShellScript" After="InstallFiles"><![CDATA[NOT Installed]]></Custom>
</InstallExecuteSequence>

<!-- Define custom action to run a PowerShell script-->
<Fragment>
  <!-- Ensure PowerShell is installed and obtain the PowerShell executable location -->
  <Property Id="POWERSHELLEXE">
    <RegistrySearch Id="POWERSHELLEXE"
                    Type="raw"
                    Root="HKLM"
                    Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
                    Name="Path" />
  </Property>
  <Condition Message="This application requires Windows PowerShell.">
    <![CDATA[Installed OR POWERSHELLEXE]]>
  </Condition>

  <!-- Define the PowerShell command invocation -->
  <SetProperty Id="RunPowerShellScript"
           Before ="InstallFiles"
           Sequence="execute"
           Value ="&quot;[POWERSHELLEXE]&quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[#ShutdownIExplore.ps1]' ; exit $$($Error.Count)&quot;" />
</Fragment>

当我运行我创建的安装程序时,我收到以下错误(来自日志):

When I run the installer I have created I get the following error (from log):

MSI (s) (DC:F8) [11:21:46:424]: Executing op: ActionStart(Name=RunPowerShellScript,,)
Action 11:21:46: RunPowerShellScript. 
MSI (s) (DC:F8) [11:21:46:425]: Executing op: CustomActionSchedule(Action=RunPowerShellScript,ActionType=1025,Source=BinaryData,Target=CAQuietExec,)
MSI (s) (DC:9C) [11:21:46:459]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI8228.tmp, Entrypoint: CAQuietExec
CAQuietExec:  Error 0x80070057: failed to get command line data
CAQuietExec:  Error 0x80070057: failed to get Command Line
CustomAction RunPowerShellScript returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 11:21:46: InstallFinalize. Return value 3.

我完全不清楚这个错误想表达什么.我的内部参考是坏的吗?执行脚本的命令是坏的吗?还有什么?

I am not at all clear what this error is trying to say. Are my internal references bad? Is the command to execute the script bad? Something else?

非常感谢任何帮助,并提前致谢.

Any help is most appreciated and thanks in advance.

推荐答案

看起来您已将 CAQuietExec 操作安排为延迟.在这种情况下,您必须通过名为 QtExecDeferred 的 CustomActionData 属性传递要执行的命令行,该属性写入执行脚本.然后,延迟操作可以从脚本访问该属性.

Looks like you have scheduled the CAQuietExec action as deferred. In this case you have to pass the command line to be executed via a CustomActionData property called QtExecDeferred which is written to the execution script. The deferred action can then access the property from the script.

更多详情请见http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html

这篇关于从 WiX 安装程序运行 PowerShell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆