Wix - 安装然后运行 ​​powershell 脚本 [英] Wix - install and then run a powershell script

查看:33
本文介绍了Wix - 安装然后运行 ​​powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know that there are several posts on Wix and PowerShell scripts, but after trying the solutions from those posts, I am still not getting my desired results. To explain my situation, I have created a Wix setup project that will grab 2 Powershell scripts and an msu file from my local machine (running windows 7) and bundle these into an msi file. if I run the msi file on my test virtual machine (running windows server 2008 r2) the files get copied into their specified directory. Great. There is a downside of having a new item show in the Add/Remove programs list, but that would be something I would approach at a later date.

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

(the Powershell scripts will install the msu, edit a config file and start a service - works fine when running manually)

在将文件复制到目标机器上后,我试图做的是运行复制的 Powershell 脚本之一,但到目前为止我还没有能够做到这一点.

What I've tried to do after getting the files copied onto the target machine is to run one of the copied Powershell scripts, but so far I've not been able to achieve this.

我的 .wxs 代码如下所示(使用 TFS 2010 编写和编译)

my .wxs code looks like this (written and compiled using 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 时没有任何反应.这些文件不像以前那样出现在它们的文件夹中,也没有安装任何东西.谁能告诉我我哪里出错了?如上所述,网上有几种解决类似问题的解决方案,但到目前为止没有一个对我有用

Since adding the custom activity to carry out the powershell script, nothing happens when I run the msi. The files do not appear in their folder like they used to and nothing is installed . Can anyone tell me where I'm going wrong? As said, there are several solutions on the net about similar issues but none have worked for me so far

更新

我尝试在打开日志记录的情况下安装 msi,并且日志返回以下 2 行:

I have tried installing the msi with logging turned on, and the log returned the following 2 lines:

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

CAQuietExec64: Error 0x80070057: failed to get command line data

CAQuietExec64:错误 0x80070057:获取命令行失败

CAQuietExec64: Error 0x80070057: failed to get Command Line

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

After searching the net for fixes for that error code, I still have not found any answers to help solve the problem. Anyone got any ideas? Any Wix experts out there?

提前致谢

推荐答案

你显然和我从同一个站点得到了这个例子......你发现了一个错误,但没有找到另一个 :-)

you obviously got this example from the same site as me... you found one of the errors, but not the other one :-)

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

In your SetProperty Id="RunPScript" node, you need to change the [POWERSHELL.EXE] TO [POWERSHELLEXE] as per how it is defined in the property above where you retrieve the path from the registry.

这篇关于Wix - 安装然后运行 ​​powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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