Window handle of UI window

Mar 28, 2016 at 11:09 PM
I show the user a MessageBox from a custom action, and I need to pass the window handle of the install dialog as the first parameter to MessageBox.Show(), so the user can't click behind it and continue with the installation. Right now I use

FindWindow(null, "Installing " + e.ProductName)

to get it, but I'd rather have a more robust way of getting this. Since I am using the ManagedUI, ManagedUIShell looks like what I need, but it's not available in the custom action. Any good way of accessing its HWND?

By the way you are doing a terrific job on this, I've written installers for years, and this seems like the best way yet.
Mar 29, 2016 at 11:35 PM
Edited Mar 30, 2016 at 11:16 PM
Technically you still can do FindWindow. The MSI still does the same nasty stuff by executing every custom action in a separate external process.

Though you can also use the UIShell member of the managed setup event argument to access the handle:
project.UILoaded += UILoaded;
static void UILoaded(SetupEventArgs e)
    MessageBox.Show((e.ManagedUIShell as Form).Handle.ToString());
If you need to pass it to a generic (non-event) managed custom action then you will need to save the handle to e.Session["UI_HANDLE"] and then read it in the custom action body.

Though the latest HotFix release v1.0.34.3 has delivered the change that assists you directly with the task:
  • Release notes: Added SetupEventArgs.ManagedUIHandle and WIXSHARP_MANAGED_UI_HANDLE session property
Mar 30, 2016 at 2:02 PM
That's terrific, thanks!
Apr 6, 2016 at 4:44 PM
And I did just try the hotfix and it works. This is a nice touch, much better than relying on FindWindow().