簡體   English   中英

Wix - 安裝並運行 powershell 腳本

[英]Wix - install and then run a powershell script

我知道 Wix 和 PowerShell 腳本上有幾篇文章,但是在嘗試了這些文章的解決方案之后,我仍然沒有得到我想要的結果。 為了解釋我的情況,我創建了一個 Wix 安裝項目,它將從我的本地計算機(運行 windows 7)中獲取 2 個 Powershell 腳本和一個 msu 文件並將它們捆綁到一個 msi 文件中。 如果我在我的測試虛擬機上運行 msi 文件(運行 windows server 2008 r2),文件將被復制到它們指定的目錄中。 偉大的。 在“添加/刪除程序”列表中顯示新項目有一個缺點,但這是我以后會處理的事情。

(Powershell 腳本將安裝 msu,編輯配置文件並啟動服務 - 手動運行時工作正常)

將文件復制到目標計算機后,我嘗試執行的操作是運行復制的 Powershell 腳本之一,但到目前為止我還沒有實現這一點。

my.wxs 代碼如下所示(使用 TFS 2010 編寫和編譯)

<?xml version="1.0" encoding="UTF-8"?>
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    <Product Id="a89cc681-d617-43ea-817e-1db89b941bf2" Name="Test1" Language="1033" Version="1.0.0.0" Manufacturer="Test1" UpgradeCode="d8db2663-2567-4bb8-9023-09988838eb55">
    <Package InstallerVersion="200" Compressed="yes" />

<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

<!-- Set up the directory -->
<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="IISTIERINSTALLATION" Name="IISTierInstallation">
  </Directory>
</Directory>

<!-- Copy the files -->
<DirectoryRef Id="IISTIERINSTALLATION">
    <Component Id ="C2WTS_update_file" Guid="11960C39-12EB-4777-B43F-394ADB352DD3">
      <File Id="C2WTSmsu" Name="Windows6.1-KB974405-x64.msu" Source="C:\PS Scripts\Windows6.1-KB974405-x64.msu" />
    </Component>

    <Component Id ="C2WTSInstallScript" Guid="C85ED4DB-BDC1-4DD1-84FE-41D7463C6365">
      <File Id="C2WTSscript1" Name="C2WTS_service_install.ps1" Source="C:\PS Scripts\C2WTS_service_install.ps1" />
    </Component>

    <Component Id ="C2WTSxmlScript" Guid="AF1F85A7-88F7-4BBA-89D9-6817CFAA74F9">
      <File Id="C2WTSscript2" Name="Edit_c2wts_config.ps1" Source="C:\PS Scripts\Edit_c2wts_config.ps1" />
    </Component>
</DirectoryRef>

    <Feature Id="ProductFeature" Title="Test1" Level="1">
        <ComponentRef Id="C2WTS_update_file" />
  <ComponentRef Id="C2WTSInstallScript" />
  <ComponentRef Id="C2WTSxmlScript" />
        <ComponentGroupRef Id="Product.Generated" />
    </Feature>

<!-- Run custom action to run the powershell script-->
<Property Id="POWERSHELLEXE">
  <RegistrySearch Id="POWERSHELLEXE"
                  Type="raw"
                  Root="HKLM"
                  Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
                  Name="Path" />
</Property>

<SetProperty Id="RunPSscript"
         After="InstallFiles"
         Sequence="execute"
         Value ="&quot;[POWERSHELL.EXE]&quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[#C2WTS_service_install.ps1]' ; exit $$($Error.Count)&quot;" />

<CustomAction Id="RunPSscript"
              BinaryKey="WixCA"
              DllEntry="CAQuietExec"
              Execute="deferred"
              Return="check"
              Impersonate="yes" />

  <Custom Action="RunPSscript" After="InstallFiles">
    <![CDATA[NOT Installed]]>
  </Custom>

</Product>
</Wix>

由於添加了自定義活動來執行 powershell 腳本,所以當我運行 msi 時沒有任何反應。 這些文件不像以前那樣出現在他們的文件夾中,也沒有安裝任何東西。 誰能告訴我哪里出錯了? 如前所述,網上有幾種關於類似問題的解決方案,但到目前為止沒有一個對我有用

更新

我嘗試在打開日志的情況下安裝 msi,日志返回以下 2 行:

CAQuietExec64:錯誤 0x80070057:無法獲取命令行數據

CAQuietExec64:錯誤 0x80070057:無法獲取命令行

在網上搜索該錯誤代碼的修復程序后,我仍然沒有找到任何答案來幫助解決問題。 有人有什么想法嗎? 那里有任何 Wix 專家嗎?

提前致謝

您顯然是從與我相同的站點獲得此示例...您發現了其中一個錯誤,但沒有發現另一個錯誤:-)

在您的SetProperty Id="RunPScript"節點中,您需要根據上面從注冊表中檢索路徑的屬性中的定義方式將 [ POWERSHELL.EXE ] 更改為[POWERSHELLEXE]

嘗試在執行 SetProperty 時進行更改。

看起來 SetProperty 元素在“InstallFiles”之后調用,並且自定義操作也設置為在“InstallFiles”之后運行。 您可以嘗試更改 SetProperty 元素以在“InstallFiles”之前執行,如下所示:

<SetProperty Id="RunPSscript"
     Before="InstallFiles"
     Sequence="execute"
     Value ="&quot;[POWERSHELL.EXE]&quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[#C2WTS_service_install.ps1]' ; exit $$($Error.Count)&quot;" />

rest 看起來不錯,盡管我通常將自定義操作包裝在 InstallExecuteSequence 元素中。

<InstallExecuteSequence>
    <Custom Action="RunPSscript" After="InstallFiles"><![CDATA[NOT Installed]]>/Custom>
</InstallExecuteSequence>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM