我發現了幾個示例,展示瞭如何從WiX運行PowerShell腳本,但未能成功運行它們中的任何一個。所以,我想發佈我所期望的,希望有人能指出我做錯了什麼。從WiX安裝程序運行PowerShell腳本
<!--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 =""[POWERSHELLEXE]" -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& '[#ShutdownIExplore.ps1]' ; exit $$($Error.Count)"" />
</Fragment>
當我跑我已經創建了安裝程序,我得到以下錯誤(從日誌):
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.
我並不清楚這個錯誤是什麼想說的。我的內部引用不好嗎?命令是否執行腳本不好?還有別的嗎?
任何幫助是最感謝和提前感謝。
注意添加'-Version 2.0'可能不再默認情況下,在Windows上工作8/Windows的Server 2012的這是由於.NET Framework 2.0的(或3.5)默認情況下不安裝在服務器上。 PowerShell 4.0使用.NET Framework 4.0(因此它不會安裝NetFx2),所以如果您嘗試執行'powershell -Version 2.0',則會出現錯誤。最好製作適用於所有版本的PowerShell 2及更高版本的腳本。注意這個答案http://stackoverflow.com/a/13865175/18475 – ferventcoder