【问题标题】:Wix - install and then run a powershell scriptWix - 安装然后运行 ​​powershell 脚本
【发布时间】:2011-07-20 14:09:04
【问题描述】:

我知道有几篇关于 Wix 和 PowerShell 脚本的帖子,但是在尝试了这些帖子中的解决方案后,我仍然没有得到我想要的结果。为了解释我的情况,我创建了一个 Wix 安装项目,它将从我的本地计算机(运行 Windows 7)中获取 2 个 Powershell 脚本和一个 msu 文件,并将它们捆绑到一个 msi 文件中。如果我在我的测试虚拟机(运行 windows server 2008 r2)上运行 msi 文件,这些文件将被复制到它们指定的目录中。伟大的。在“添加/删除程序”列表中显示新项目有一个缺点,但我会在以后处理。

(Powershell 脚本将安装 msu、编辑配置文件并启动服务 - 手动运行时工作正常)

在将文件复制到目标计算机后,我尝试执行的操作是运行复制的 Powershell 脚本之一,但到目前为止我还无法实现这一点。

我的 .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 专家吗?

提前致谢

【问题讨论】:

  • 通过生成安装日志开始故障排除(运行 msiexec.exe /i {your msi file here} /log {path to log}。

标签: powershell wix


【解决方案1】:

您显然是从与我相同的站点获得此示例...您发现了其中一个错误,但没有发现另一个错误 :-)

在您的 SetProperty Id="RunPScript" 节点中,您需要将 [POWERSHELL.EXE] 更改为 [POWERSHELLEXE]它是如何在上面的属性中定义的,您从注册表中检索路径。

【讨论】:

    【解决方案2】:

    尝试在 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;" />
    

    尽管我通常将自定义操作包装在 InstallExecuteSequence 元素中,但其余部分看起来还不错。

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

    【讨论】:

      猜你喜欢
      • 2012-12-12
      • 2011-01-24
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2010-11-26
      • 2022-01-08
      • 2010-10-03
      相关资源
      最近更新 更多