0

I want to make an installer run a PowerShell script, before installing all the other files. However, how it is build currently, it only works to run the script when the install is done, because it is placing the powershell script in the target directory. Now this could probably be fixed by making the directory something that is always existing. However, I don't want to have to provide the script with the installer all the time, I want the script to be embedded into the installer and run from there or at least run the commands that are in the script file.

I tried changing the custom action's "After" to "InstallInitialize", however it throws an error saying it can't the path (which is logical, because the path isn't created yet because the script is executed before the installation of the files).

Here is a bit of the code where all the logic for running the powershell script is provided:

<DirectoryRef Id="INSTALLFOLDER">
  <Component Id ="SOMESCRIPT" Guid="">
    <File Id="SOMESCRIPT" Name="My-Script.ps1" Source="My-Script.ps1" />
  </Component>
</DirectoryRef>

<Property Id="POWERSHELLEXE">
  <RegistrySearch Id="POWERSHELLEXE"
                  Type="raw"
                  Root="HKLM"
                  Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
                  Name="Path" />
</Property>

<Condition Message="This application requires Windows PowerShell.">
  <![CDATA[Installed OR POWERSHELLEXE]]>
</Condition>

<SetProperty Id="PSscript"
         After="PSscript"
         Sequence="execute"
         Value ="&quot;[POWERSHELLEXE]&quot; -Version 3.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[#SOMESCRIPT]' ; exit $$($Error.Count)&quot;" />

<CustomAction Id="PSscript"
              BinaryKey="WixCA"
              DllEntry="WixQuietExec"
              Execute="deferred"
              Return="check"
              Impersonate="yes" />

<InstallExecuteSequence>
  <Custom Action="PSscript" After="InstallInitialize"><![CDATA[NOT Installed]]></Custom>
</InstallExecuteSequence>

The Expected result is the script being embedded into the .msi file, not relying on a file that is only created after installation. The error message is that it can't find the script because it isn't installed yet. I actually don't want the script file to be placed in the folder to begin with, I just want the script run inside the installer and do nothing else with the script file.

1 Answer 1

1

This the only PS extension of Wix I could find online, but it seems this could be limited to your scenario too.

To support running scripts before they are installed we (at Advanced Installer) created a predefined support to extract the PS script as a temporary file when the installation is launched and execute it from that temp location. I don't if Wix has a similar support.

Disclosure: I work on the team building Advanced Installer.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey, thanks for the reply. This extension would fix the problem of not finding (or the need of) a file, since it can run an in-line script. The only problem I have with this extension is that it always runs powershell in 32-bit. I couldn't find a way to get it to launch powershell in 64-bit. In the end I just ended up going the after installfinalize route, by changing the order at which certain operations where executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.