' +----------------------------------------------------------------------------+ ' | Jeffrey M. Hunter | ' | jhunter@idevelopment.info | ' | www.idevelopment.info | ' |----------------------------------------------------------------------------| ' | Copyright (c) 1998-2011 Jeffrey M. Hunter. All rights reserved. | ' |----------------------------------------------------------------------------| ' | FILE : DisplayPopupMessage.vbs | ' | CLASS : Miscellaneous Functions | ' | PURPOSE : Demonstrates how to display a WSH popup message box. | ' | PARAMETERS : None | ' | USAGE : cscript DisplayPopupMessage.vbs //NoLogo | ' | NOTE : As with any code, ensure to test this script in a development | ' | environment before attempting to run it in production. | ' +----------------------------------------------------------------------------+ Option Explicit ' ----------------------------------------------------------------------------- ' SET GLOBAL VARIABLES AND ANY OBJECTS ' ----------------------------------------------------------------------------- Const g_S_MARK = 16 ' Stop Mark Const g_Q_MARK = 32 ' Question Mark Const g_E_MARK = 48 ' Exclamation Mark Const g_I_MARK = 64 ' Information Mark Const g_BUTTON_OK = 0 ' Ok Button Const g_BUTTON_OC = 1 ' Ok, Cancel Button Const g_BUTTON_ARI = 2 ' Abort, Retry, Ignore Const g_BUTTON_YNC = 3 ' Yes, No, Cancel Const g_BUTTON_YN = 4 ' Yes, No Const g_BUTTON_RC = 5 ' Retry, Cancel Const g_DEFAULT_TIMEOUT = 5 ' Default timeout value for all popup message ' boxes. Const g_NO_TIMEOUT = 0 ' Used to specify no timeout is to occur for ' popup message boxes. Dim g_objShell ' Global WSH Shell Object Set g_objShell = CreateObject("WScript.Shell") Dim g_MAIN_RETURN ' Return value for Main. Used to return value ' to the calling program or operating environment. ' ----------------------------------------------------------------------------- ' - CALL MAIN FUNCTION ' - THEN CLEAN UP OBJECTS AND EXIT SCRIPT ' ----------------------------------------------------------------------------- g_MAIN_RETURN = Main Set g_objShell = Nothing WScript.Quit(g_MAIN_RETURN) ' ////////////////////////////////////////////////////////////////////////////// ' | TimeoutExample ' | ' | Message box example that demonstrates how to timeout the dialog after a ' | amount of time (in seconds). This example uses a message box with an ' | Information Mark icon. ' | ' | Returns ' | Returns an integer value that corresponds to the button clicked by ' | the user. ' | ' | OK = 1 ' | Timeout = -1 ' ////////////////////////////////////////////////////////////////////////////// Function TimeoutExample Dim strMessage, strTitle, intResult strTitle = "Message Box - (Timeout)" strMessage = "Message Box Popup Examle - (Timeout)" intResult = g_objShell.Popup(strMessage, g_DEFAULT_TIMEOUT, strTitle, g_BUTTON_OK + g_I_MARK) TimeoutExample = intResult End Function ' ////////////////////////////////////////////////////////////////////////////// ' | YesNoCancelExample ' | ' | Message box example that demonstrates how to use a Yes, No, Cancel popup ' | dialog. This example will use the Exclamation Mark for the message box icon ' | and will specify a value of 0 for the timeout - indicating that no timeout ' | should occur for this message box. ' | ' | Returns ' | Returns an integer value that corresponds to the button clicked by ' | the user. ' | ' | Yes = 6 ' | No = 7 ' | Cancel = 2 ' ////////////////////////////////////////////////////////////////////////////// Function YesNoCancelExample Dim strMessage, strTitle, intResult strTitle = "Message Box - (Yes, No, Cancel)" strMessage = "Message Box Popup Examle - (Yes, No, Cancel)" intResult = g_objShell.Popup(strMessage, g_NO_TIMEOUT, strTitle, g_BUTTON_YNC + g_E_MARK) YesNoCancelExample = intResult End Function ' ////////////////////////////////////////////////////////////////////////////// ' | AbortRetryIgnoreExample ' | ' | Message box example that demonstrates how to use a Abort, Retry, Ignore ' | popup dialog. This example will use the Stop Mark for the message box icon ' | and will specify a value of 0 for the timeout - indicating that no timeout ' | should occur for this message box. ' | ' | Returns ' | Returns an integer value that corresponds to the button clicked by ' | the user. ' | ' | Abort = 3 ' | Retry = 4 ' | Ignore = 5 ' ////////////////////////////////////////////////////////////////////////////// Function AbortRetryIgnoreExample Dim strMessage, strTitle, intResult strTitle = "Message Box - (Abort, Retry, Ignore)" strMessage = "Message Box Popup Examle - (Abort, Retry, Ignore)" intResult = g_objShell.Popup(strMessage, g_NO_TIMEOUT, strTitle, g_BUTTON_ARI + g_S_MARK) AbortRetryIgnoreExample = intResult End Function ' ////////////////////////////////////////////////////////////////////////////// ' | Main ' | ' | Main function used to enclose the primary script logic. ' | ' | Returns ' | Exit code from primary script logic. ' ////////////////////////////////////////////////////////////////////////////// Function Main Dim intPopupResult ' ----------------------------------------- ' Timeout Example ' ----------------------------------------- WScript.Echo "Message Box Popup Example - (Timeout)" intPopupResult = timeoutExample If (intPopupResult = 1) Then WScript.Echo "You hit [OK]." Elseif (intPopupResult = -1) Then WScript.Echo "Timeout occured." Else WScript.Echo "Unexpected Exception." WScript.Echo "Popup Result: " & intPopupResult End If ' ----------------------------------------- ' Yes / No / Cancel Example ' ----------------------------------------- WScript.Echo "" WScript.Echo "Message Box Popup Example - (Yes, No, Cancel)" intPopupResult = yesNoCancelExample If (intPopupResult = 6) Then WScript.Echo "You hit [Yes]." Elseif (intPopupResult = 7) Then WScript.Echo "You hit [No]." Elseif (intPopupResult = 2) Then WScript.Echo "You hit [Cancel]." Else WScript.Echo "Unexpected Exception." WScript.Echo "Popup Result: " & intPopupResult End If ' ----------------------------------------- ' Abort, Retry, Ignore ' ----------------------------------------- WScript.Echo "" WScript.Echo "Message Box Popup Example - (Abort, Retry, Ignore)" intPopupResult = abortRetryIgnoreExample If (intPopupResult = 3) Then WScript.Echo "You hit [Abort]." Elseif (intPopupResult = 4) Then WScript.Echo "You hit [Retry]." Elseif (intPopupResult = 5) Then WScript.Echo "You hit [Ignore]." Else WScript.Echo "Unexpected Exception." WScript.Echo "Popup Result: " & intPopupResult End If Main = 0 End Function