Keeping MsgBox On-Top

by Jun 4, 2013

When you open a MsgBox dialog from PowerShell, the dialog window may sometimes not be visible and instead appears behind the PowerShell or ISE window.

To make sure a MsgBox dialog box appears in front of your PowerShell window, try this:

Add-Type -AssemblyName Microsoft.VisualBasic

[Microsoft.VisualBasic.Interaction]::MsgBox('My message', 'YesNo,MsgBoxSetForeground,Information', 'MyTitle')

Key is the option "MsgBoxSetForeground". If you'd like to know what other options you can choose from, replace the second argument with nonsense text, and the error message will list all the other option names.

One is "SystemModal". If you use that instead of "MsgBoxSetForeground", then the MsgBox will not only appear in front, it will stay there. No other window can then overlap the dialog box until the user clicked one of its buttons.

Twitter This Tip! ReTweet this Tip!