3

I have an MSI, written with WiX, that calls a third party application as part of the setup process. I can get the app to execute, however it opens in the background, behind the installer. Is there any way to have the app appear in front of the installer?

The app in question requires elevated privileges, so running it from the Finish dialog is not an option.

2 Answers2

0

Are you using an EXE command? I believe this custom action extension runs programs in the front. If not, you could always write your own.

How To: Run the Installed Application After Setup

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Your suggestion allowed me to run the app from the Finish dialog with elevated privileges, which is much appreciated. Unfortunately, it doesn't solve my problem: the new app still sometimes starts up behind another window. – Soren Petersen Oct 02 '14 at 15:29
  • Can you modify your app to come to the foreground when launched? – Christopher Painter Oct 02 '14 at 16:09
  • It's not my app, I'm afraid. I suppose I could write my own wrapper that comes to the foreground and then launches the app, but I'd like to avoid that kind of acrobatics if at all possible. – Soren Petersen Oct 02 '14 at 17:31
0

I just recently figured the best way to do this. I pieced it together from multiple sources. This is for C# Custom action launching an exe. You can also just launch the exe by a Wix ExeCommand and use the custom action to bring it forward after manually finding the correct process.

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern IntPtr GetTopWindow(IntPtr hWnd);

static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); 

const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_SHOWWINDOW = 0x0040;

[CustomAction]
public static ActionResult BringExeForward(Session session)
{

    ProcessStartInfo processInfo = new ProcessStartInfo("Application.exe");
    Process bProcess = Process.Start(processInfo);

    while (GetTopWindow((IntPtr)null) != bProcess.MainWindowHandle)
    {
        SetWindowPos(bProcess.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    }

    SetWindowPos(bProcess.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

    return ActionResult.Success;

}
Dtagg
  • 68
  • 8