Wix - 安装然后运行powershell脚本

Ver*_*min 6 powershell wix

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

(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>
Run Code Online (Sandbox Code Playgroud)

由于添加自定义活动以执行powershell脚本,因此在运行msi时没有任何反应.这些文件不像过去那样出现在文件夹中,也没有安装任何文件.谁能告诉我哪里出错了?如上所述,网上有几个关于类似问题的解决方案,但到目前为止还没有一个对我有用

UPDATE

我已经尝试安装msi并启用了日志记录,日志返回以下两行:

CAQuietExec64:错误0x80070057:无法获取命令行数据

CAQuietExec64:错误0x80070057:无法获取命令行

在网上搜索该错误代码的修复程序后,我仍然没有找到任何答案来帮助解决问题.有人有任何想法吗?那里有任何Wix专家吗?

提前致谢

Dar*_*ren 0

尝试在执行 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;" />
Run Code Online (Sandbox Code Playgroud)

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

<InstallExecuteSequence>
    <Custom Action="RunPSscript" After="InstallFiles"><![CDATA[NOT Installed]]>/Custom>
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)