Search code examples
wixwindows-installernsis

Application does not alway come to top after an install and start app


We have an installer system based on a WIX built MSI. The boot strapper is NSIS. It is just the way things went. And it all works fine now but for one little glitch.

There are two NSIS installers. One for new users. That runs the MSI conventionally so they contract screen can be agreed to. The the app checks for updates and the user can do just that. This is the second NSIS package for that:

Section -RA_unzip
    InitPluginsDir
    ReadRegStr $R1 HKCU "Software\Company\AppFolder\Property" "User Directory"
    SetOutPath $R1
    File "f:\cpp\AppName\deployment\AppName.msi"
    ExecWait 'msiexec /i "$R1\AppName.msi" /L* msi.log /passive /norestart' $0
SectionEnd
      
Section -r_name_dlls
    ReadRegStr $R0 HKCU "Software\Company\AppFolder\Property" "Program Directory"
    Rename $R0\libssl_3.dll $R0\libssl-3.dll
    Rename $R0\libcrypto_3.dll $R0\libcrypto-3.dll
SectionEnd

Section -Finishing Up
    Sleep 1000
SectionEnd

Section -restartRA
    ReadRegStr $R0 HKCU "Software\Company\AppFolder\Property" "Program Directory"
    Exec $R0\ars.exe
    Quit
SectionEnd

Less than half of the time the application comes up to the top of the Z-order. Sometimes it ends up at the bottom! This happens on my Windows7 and my wife's Windows10. If I run this without bumping the MSI version, (It just quits without an install), then the app window will always make it to the top.

I've even added BringWindowToTop(*GetMainWnd()); at the end of initialization when the main window is well established and running. And I did think it had something to do with the windows installer being slow to leave, that is why the Sleep 1000. It made no difference.

The only thing that is for sure is it happens when the windows installer actually does an install.


Solution

  • Calling Quit directly after Exec is not a good idea because if the installer quits before the child process has displayed its window the right to set the foreground window is lost.

    You could try

    ExecShell /WAITFORINPUTIDLE "" "$R0\ars.exe"
    Sleep 1000
    Quit