Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > User Interaction > Progress Messages

Progress Messages

by Denis St-Pierre

 

WSH (MsgBox)
VBScript Code:
Function ProgressMsg( strMessage, strWindowTitle )
' Written by Denis St-Pierre
' Displays a progress message box that the originating script can kill in both 2k and XP
' If StrMessage is blank, take down previous progress message box
' Using 4096 in Msgbox below makes the progress message float on top of things
' CAVEAT: You must have   Dim ObjProgressMsg   at the top of your script for this to work as described
    Set wshShell = CreateObject( "WScript.Shell" )
    strTEMP = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
    If strMessage = "" Then
        ' Disable Error Checking in case objProgressMsg doesn't exists yet
        On Error Resume Next
        ' Kill ProgressMsg
        objProgressMsg.Terminate( )
        ' Re-enable Error Checking
        On Error Goto 0
        Exit Function
    End If
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strTempVBS = strTEMP + "\" & "Message.vbs"     'Control File for reboot

    ' Create Message.vbs, True=overwrite
    Set objTempMessage = objFSO.CreateTextFile( strTempVBS, True )
    objTempMessage.WriteLine( "MsgBox""" & strMessage & """, 4096, """ & strWindowTitle & """" )
    objTempMessage.Close

    ' Disable Error Checking in case objProgressMsg doesn't exists yet
    On Error Resume Next
    ' Kills the Previous ProgressMsg
    objProgressMsg.Terminate( )
    ' Re-enable Error Checking
    On Error Goto 0

    ' Trigger objProgressMsg and keep an object on it
    Set objProgressMsg = WshShell.Exec( "%windir%\system32\wscript.exe " & strTempVBS )

    Set wshShell = Nothing
    Set objFSO   = Nothing
End Function
Requirements:
Windows version: any
Network: N/A
Client software: N/A
Script Engine: any
Summarized: Works in any Windows version.
 
[Back to the top of this page]
 
Usage Sample:
' Makes the object a Public object (Critical!)
Dim objProgressMsg

' *** Usage example
strWindowTitle = "AppName_1_0"
ProgressMsg "Installing, Please wait.", strWindowTitle
' Do work here that will take a long time
WScript.Sleep 3000

ProgressMsg "I'm installing app #2, Please wait.", strWindowTitle
WScript.Sleep 3000

' Removes previous ProgressMsg
ProgressMsg "", strWindowTitle
WScript.Sleep 3000

' Doing it this way leaves the msgbox
ProgressMsg "Done", strWindowTitle
WScript.Quit
' *** End Usage example
 
[Back to the top of this page]

page last uploaded: 2016-09-19, 14:58