0

I'm new to using WixToolset, I'm trying to execute a ps1 file using WixQuietExec - https://wixtoolset.org/docs/v3/customactions/qtexec/. The ps1 script works in general if I execute it directly using powershell. It fails with WixQuietExec

I used the below in my product.wxs

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

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

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

    <InstallExecuteSequence>
        <Custom Action="SysShell" Before="InstallFinalize">
            <![CDATA[NOT Installed]]>
        </Custom>
    </InstallExecuteSequence>

I'm able to generate MSI build but when I try to install the MSI, I get the below error logs which doesn't exactly specify the command line error and the MSI installation fails.

MSI (s) (E8:C4) [13:41:56:992]: Executing op: ActionStart(Name=SysShell,,)
MSI (s) (E8:C4) [13:41:56:992]: Executing op: CustomActionSchedule(Action=SysShell,ActionType=3073,Source=BinaryData,Target=WixQuietExec,CustomActionData="C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& 'C:\Program Files\UpdateFile\EventLog.ps1' ; exit $($Error.Count)")
MSI (s) (E8:C4) [13:41:57:000]: Creating MSIHANDLE (2) of type 790536 for thread 10436
MSI (s) (E8:50) [13:41:57:000]: Invoking remote custom action. DLL: C:\Windows\Installer\MSIC226.tmp, Entrypoint: WixQuietExec
MSI (s) (E8:1C) [13:41:57:000]: Generating random cookie.
MSI (s) (E8:1C) [13:41:57:017]: Created Custom Action Server with PID 4160 (0x1040).
MSI (s) (E8:C8) [13:41:57:098]: Running as a service.
MSI (s) (E8:C8) [13:41:57:098]: Hello, I'm your 32bit Elevated Non-remapped custom action server.
MSI (s) (E8!E4) [13:42:03:824]: Creating MSIHANDLE (3) of type 790531 for thread 14820
WixQuietExec:  Error 0x80070007: Command line returned an error.
MSI (s) (E8!E4) [13:42:03:825]: Closing MSIHANDLE (3) of type 790531 for thread 14820
MSI (s) (E8!E4) [13:42:03:825]: Creating MSIHANDLE (4) of type 790531 for thread 14820
WixQuietExec:  Error 0x80070007: QuietExec Failed
MSI (s) (E8!E4) [13:42:03:825]: Closing MSIHANDLE (4) of type 790531 for thread 14820
MSI (s) (E8!E4) [13:42:03:826]: Creating MSIHANDLE (5) of type 790531 for thread 14820
WixQuietExec:  Error 0x80070007: Failed in ExecCommon method
MSI (s) (E8!E4) [13:42:03:827]: Closing MSIHANDLE (5) of type 790531 for thread 14820
CustomAction SystemShell returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (s) (E8:50) [13:42:03:828]: Closing MSIHANDLE (2) of type 790536 for thread 10436
Action ended 13:42:03: InstallFinalize. Return value 3.

Any guidance regarding this issue is truly appreciated. Thank you.

I've read other stackoverflow references Run PowerShell script from WiX installer and other online blogs https://0ptikghost.blogspot.com/2011/03/executing-powershell-scripts-silently.html but nothing works.

2
  • The WixQuietExec error code looks scary, but I think it's misleading. You are setting the number of errors as the exit code of your custom action (exit $$($Error.Count)), so what you see in the log is propably just the number of errors (7) translated into an HRESULT code. To learn more about the problem, I suggest you write a log file from your PowerShell script. Commented Nov 16, 2023 at 10:53
  • Thanks for your comment. I've posted the answer which worked for me. Commented Nov 17, 2023 at 14:58

1 Answer 1

1

Using -File instead of -Command inside SetProperty worked for me.

        <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="SystemShell"
                Before="SystemShell"
                Sequence="execute"
                Value ="&quot;[POWERSHELLEXE]&quot; -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -File &quot;[#CreateEventLogPS1]&quot;" />

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

        <InstallExecuteSequence>
            <Custom Action="SystemShell" Before="InstallFinalize">
                <![CDATA[NOT Installed]]>
            </Custom>
        </InstallExecuteSequence>

Not related to this but the powershell process created here is not able to access registry. I've posted a different question for the same Wix Custom Action always creates 32 bit powershell process. How to make it to create a 64 bit process?

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

Comments

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.