Updated: September 2010
Displays text in a pop-up message box.
intButton = object.Popup(strText,[nSecondsToWait],[strTitle],[nType])
The Popup method displays a message box regardless of which host executable file is running (WScript.exe or CScript.exe).
If nSecondsToWait equals zero (the default), the pop-up message box remains visible until closed by the user. If nSecondsToWaitis is greater than zero, the pop-up message box closes after nSecondsToWait seconds.
If you do not supply the argument strTitle, the title of the pop-up message box defaults to "Windows Script Host."
Type Parameter
The meaning of the nType parameter is the same as it is in the Microsoft Win32 API MessageBox function. The following tables show the values and their meanings. You can add values in these tables to combine them.
|
Decimal value |
Hexadecimal value |
Description |
|---|---|---|
|
0 |
0x0 |
Show OK button. |
|
1 |
0x1 |
Show OK and Cancel buttons. |
|
2 |
0x2 |
Show Abort, Retry, and Ignore buttons. |
|
3 |
0x3 |
Show Yes, No, and Cancel buttons. |
|
4 |
0x4 |
Show Yes and No buttons. |
|
5 |
0x5 |
Show Retry and Cancel buttons. |
|
6 |
0x6 |
Show Cancel, Try Again, and Continue buttons. |
|
Decimal value |
Hexadecimal value |
Description |
|---|---|---|
|
16 |
0x10 |
Show "Stop Mark" icon. |
|
32 |
0x20 |
Show "Question Mark" icon. |
|
48 |
0x30 |
Show "Exclamation Mark" icon. |
|
64 |
0x40 |
Show "Information Mark" icon. |
|
Decimal value |
Hexadecimal value |
Description |
|---|---|---|
|
256 |
0x100 |
The second button is the default button. |
|
512 |
0x200 |
The third button is the default button. |
|
4096 |
0x1000 |
The message box is a system modal message box and appears in a topmost window. |
|
524288 |
0x80000 |
The text is right-justified. |
|
1048576 |
0x100000 |
The message and caption text display in right-to-left reading order, which is useful for some languages. |
The previous three tables do not cover all values for nType. For more information, see MessageBox Function.
Return Value
The return value intButton is the number of the button that the user clicked, or is -1 if the message box timed out. The following table lists possible return values.
|
Decimal value |
Description |
|---|---|
|
-1 |
The user did not click a button before nSecondsToWait seconds elapsed. |
|
1 |
OK button |
|
2 |
Cancel button |
|
3 |
Abort button |
|
4 |
Retry button |
|
5 |
Ignore button |
|
6 |
Yes button |
|
7 |
No button |
|
10 |
Try Again button |
|
11 |
Continue button |
The following code generates a simple pop-up message box.
Dim wshShell, btn
Set wshShell = WScript.CreateObject("WScript.Shell")
' Call the Popup method with a 7 second timeout.
btn = WshShell.Popup("Do you feel alright?", 7, "Question:", &H4 + &H20)
Select Case btn
' Yes button pressed.
case 6
WScript.Echo "Glad to hear you feel alright."
' No button pressed.
case 7
WScript.Echo "Hope you're feeling better soon."
' Timed out.
case -1
WScript.Echo "Is there anybody out there?"
End Select
var wshShell = WScript.CreateObject("WScript.Shell"); // Call the Popup method with a 7 second timeout. var btn = wshShell.Popup("Do you feel alright?", 7, "Question:", 0x4 + 0x20); switch(btn) { // Yes button pressed. case 6: WScript.Echo("Glad to hear you feel alright."); break; // No button pressed. case 7: WScript.Echo("Hope you're feeling better soon."); break; // Timed out. case -1: WScript.Echo("Is there anybody out there?"); break; }
Applies To:
Reference
|
Date |
History |
Reason |
|---|---|---|
|
September 2010 |
Added table values. |
Customer feedback. |
<#
.SYNOPSIS
This script displays a message box and then processes it
.DESCRIPTION
This script firsts creates a wscript.shell object and
invokes the popup method to display a message. The script
then processes the response to the geroup (timeout, yes, no).
.NOTES
File Name : Show-MessageBox.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://www.pshscripts.blogspot.com
MSDN sample posted tot:
http://msdn.microsoft.com/en-us/library/x83z1d9f%28VS.84%29.aspx
.EXAMPLE
Left as an exercise to the reader!
#>
# Create the shell object
$WshShell = New-Object -Com Wscript.Shell
# Call the Popup method with a 7 second timeout.
$Btn = $WshShell.Popup("Do you feel alright?", 7, "Question:", 0x4 + 0x20)
# Process the response
switch ($Btn) {
# Yes button pressed.
6 {"Glad to hear you feel alright."}
# No button pressed.
7 {"Hope you're feeling better soon."}
# Timed out.
-1 {"Is there anybody out there?"}
}