Catalin
Posts: 4358
Joined: Wed Jun 13, 2018 7:49 am

Re: Launched exe stays in background

Tue Jul 27, 2021 5:21 pm

Hello Simon,

So I just got out from a meeting with our developer.

Here are the conclusions I've reached after discussing with him + the notes from the issue I've created in our bug tracking tool.

Basically, there are 4 possible cases here:
  • If the custom action is run from under the SystemAccount (NO UI) -> NON DETERMINISTIC
  • If the custom action is run from under the LocalAccount (NO UI) -> NON DETERMINISTIC
  • If the custom action runs on the Execute Sequence as Immediately -> NON DETERMINISTIC
  • If the custom action runs on UI Sequence (Finish Dialog Stage) -> FOREGROUND
Non deterministic means that the result is relative to the UAC and is controlled by the Windows Installer. Windows Installer chooses the process under which the Custom Action runs and if that Custom Action has foreground access: AllowSetForegroundWindow function (winuser.h).

Under the "Remarks" section we can see what the conditions are for the above:
The process is the foreground process.
The process was started by the foreground process.
The process received the last input event.
There is no foreground process.
The foreground process is being debugged.
The foreground is not locked (see LockSetForegroundWindow).
The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
No menus are active.
I will attach below two screenshots, as it follows:

- when the CA is executed under the "InstallExecuteSequence" --> the CA is run from under the msiexec server process and it is launched in the background
LaunchedOnServer.png
LaunchedOnServer.png (359.58 KiB) Viewed 3959 times

- when the CA is executed under the "Finish Dialogs Stage" --> the CA is run from under the msiexec process that was launched by our bootstrapper and the executable is launched in the foreground
LaunchedOnUI.png
LaunchedOnUI.png (37.04 KiB) Viewed 3959 times


With that being said, a possible solution to this would be moving the Custom Action under the "Finish Dialogs Stage".

This way, I believe all the boxes will be ticked for you, including this one:
I don't want the actions to be performed after the "Finish" button has been clicked, since they might take some time and if they don't succeed my application won't work as expected. This is why, I want them to be performed "during" the setup, after having copied the files, before showing the finish page.
I have run the setup you have provided myself, around 30 times and everytime the executable was launched in the foreground.

Hope this will help!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

SimLoe
Posts: 60
Joined: Thu Mar 12, 2020 11:37 am

Re: Launched exe stays in background

Fri Jul 30, 2021 9:48 am

Hello Catalin,

thank you for the detailed research and explanations. I could indeed get the desired behavior by moving all those custom actions to "Finish Dialog Stage".
Just for me to understand: All actions in this stage are performed before the "Exit Dialog" is shown?

Best regards,
Simon

Catalin
Posts: 4358
Joined: Wed Jun 13, 2018 7:49 am

Re: Launched exe stays in background

Fri Jul 30, 2021 1:04 pm

Hello Simon,

Thank you for your followup on this!

It's really hard to express how glad I am everything works now. :)
Just for me to understand: All actions in this stage are performed before the "Exit Dialog" is shown?
The answer here is yes.

The behavior is actually visible, especially if you have the "Wait for custom action to finish before proceeding" option enabled for your custom action.
test.png
test.png (97.88 KiB) Viewed 3892 times

As you can see in the above screenshot, the action is executed before the "ExitDlg" dialog is shown. The setup will also wait for the custom action to finish and then proceed in displaying the "ExitDlg" dialog.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”