开发者

Wix - install and then run a powershell script

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.

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

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.

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-开发者_Python百科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>

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

UPDATE

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

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

CAQuietExec64: Error 0x80070057: failed to get Command Line

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?

Thanks in advance


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

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.


Try changing when the SetProperty is executed.

It looks like the SetProperty element is called After 'InstallFiles' and the Custom action is also set to run After 'InstallFiles'. You could try change the SetProperty element to execute Before 'InstallFiles', somethink like this:

<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;" />

The rest looks alright although I normally have the custom action wrapped in a InstallExecuteSequence element.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜