Opening MsgBoxes

by Dec 27, 2011

Need a quick message box to display something or ask a question? Fortunately, PowerShell can access old COM components. Here's a line that creates a MsgBox for 5 seconds. If the user does not make a choice within that time, it returns -1: a perfect solution for scripts that need to run unattended if no one is around.

$msg = New-Object -ComObject WScript.Shell
$msg.Popup("Hello", 5, "Title", 48)

To find out more about the Popup() method and its arguments, visit:

http://msdn.microsoft.com/en-us/library/x83z1d9f(v=VS.84).aspx

This link documents all the other WSH scripting methods as well.

Twitter This Tip!
ReTweet this Tip!