Wix - install and then run powershell script

I know that there are several posts about Wix and PowerShell scripts, but after you try to find solutions from these posts, I still do not get the desired results. To explain my situation, I created a Wix installation project that will capture 2 Powershell scripts and the msu file from my local machine (works with Windows 7) and link them to the msi file. if I run the msi file on my test virtual machine (Windows 2008 r2 server is running), the files will be copied to their specified directory. Excellent. There is a flaw in the fact that in the list of "Add / Remove Programs" there is a new view of the goods, but this will be what I would like to come up later.

(Powershell scripts install msu, edit the configuration file and start the service - they work fine when launched manually)

What I tried to do after getting the files copied to the target machine was to run one of the copied Powershell scripts, but so far I have not succeeded.

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> 

Since adding user activity to execute powershell script nothing happens when I run msi. Files do not appear in their folder, as they are used to, and nothing is installed. Can someone tell me where I am going wrong? As said, the network has several solutions to similar problems, but so far no one has worked for me.

UPDATE

I tried installing msi with logging enabled, and the log returned the following two lines:

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

CAQuietExec64: Error 0x80070057: Failed to get command line

After searching the web for fixes for this error code, I still have not found the answers to help solve the problem. Does anyone have any ideas? Do experts have Wix?

Thanks in advance

+6
source share
2 answers

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

In your identifier SetProperty Id = "RunPScript" node, you need to change [POWERSHELL.EXE] to [POWERSHELLEXE] as defined in the above property, where you extract the path from the registry.

+2
source

Try changing when SetProperty is running.

It looks like the SetProperty element is called After 'InstallFiles', and the custom action also gets triggered after the 'InstallFiles'. You can try changing the SetProperty element to execute Before 'InstallFiles', something 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 good, although usually I have a custom action wrapped in an InstallExecuteSequence element.

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

Source: https://habr.com/ru/post/893168/


All Articles