0

I'm currently trying to implement a custom action that executes a PowerShell script after the installation.

My thought about what exactly the MSI file should do is:

  1. Install/copy the Powershell script into a directory
  2. Execute this script after the installation of all files is completed

This is my current code snippet (which is not working):

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Fragment>
        <Component Id="installationScript" Guid="e74fa7d1-f7ef-4994-add6-a5cb84f04b95">
            <File Id="installationscripts" Name="unzipActiveDirectory.ps1" Source="unzipActiveDirectory.ps1"/>
        </Component>
 
        <CustomAction Id="RunPowerShellScript"
            ExeCommand="powershell.exe -ExecutionPolicy Bypass -File &quot;[InstallationScriptsFolder]unzipActiveDirectory.ps1&quot;"
            Return="check" Execute="deferred" Impersonate="no" FileRef="installationscript" />
    <InstallExecuteSequence>
      <Custom Action="RunPowerShellScript" After="InstallFinalize"></Custom>
    </InstallExecuteSequence>
 
    </Fragment>
</Wix>

I also tried another attempt from another Post that referred to a blog post. But this post was written in 2011 and is not compatible with WiX v5 anymore. The other post is also very old, so I would like to re-ask this question.

This is the code I wrote with the help of the blog post:

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Fragment>
        <Component Id="installationScript" Guid="e74fa7d1-f7ef-4994-add6-a5cb84f04b95" Directory="InstallationScriptsFolder">
            <File Id="unzipActiveDirectoryFile" Name="unzipActiveDirectory.ps1" Source="unzipActiveDirectory.ps1"/>
        </Component>
    </Fragment>
 
    <Fragment>
        <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="unzipActiveDirectoryFile"
             Before="unzipActiveDirectoryFile"
             Sequence="execute"
             Value ="&quot;[POWERSHELLEXE]&quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[#unzipActiveDirectoryFile]' ; exit $$($Error.Count)&quot;" />
        <CustomAction Id="unzipActiveDirectoryFile"
              BinaryKey="WixCA"
              DllEntry="WixQuietExec"
              Execute="deferred"
              Return="check"
              Impersonate="yes" />
        <InstallExecuteSequence>
            <Custom Action="unzipActiveDirectoryFile" After="InstallFiles">
                <![CDATA[NOT Installed]]>
            </Custom>
        </InstallExecuteSequence>
 
    </Fragment>
</Wix>

My knowledge about custom actions is very limited, so I'm really looking forward to someone who can help me.

Thank you!

1
  • I don't have a real answer, but it's worth installing the produced msi with logging enabled and seeing if the action is mentioned and what happens to it Commented Jan 24 at 12:13

0

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.