Show Message dialog while executing

25,318

Sorry, it slipped to me that i can call MsgBox just before executing, Run() :embarrassed:


Edit:

for no user interaction here is one workaround (taken from http://www.robvanderwoude.com/vbstech_ui_progress.php)

Function ProgressMsg( strMessage, strWindowTitle )
' Written by Denis St-Pierre
    Set wshShell = WScript.CreateObject( "WScript.Shell" )
    strTEMP = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
    If strMessage = "" Then
        On Error Resume Next
        objProgressMsg.Terminate( )
        On Error Goto 0
        Exit Function
    End If
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strTempVBS = strTEMP + "\" & "Message.vbs"

    Set objTempMessage = objFSO.CreateTextFile( strTempVBS, True )
    objTempMessage.WriteLine( "MsgBox""" & strMessage & """, 4096, """ & strWindowTitle & """" )
    objTempMessage.Close

    On Error Resume Next
    objProgressMsg.Terminate( )
    On Error Goto 0

    Set objProgressMsg = WshShell.Exec( "%windir%\system32\wscript.exe " & strTempVBS )

    Set wshShell = Nothing
    Set objFSO   = Nothing
End Function

Then call it with:

ProgressMsg "Installing, Please wait.", "Some title"

end terminate it with:

ProgressMsg "", "Some title"

Share:
25,318
theta
Author by

theta

Updated on July 28, 2022

Comments

  • theta
    theta almost 2 years

    I use this snippet in vbscript:

    Set WSH = CreateObject("WScript.Shell")
    cmd = "some command"
    flag = WSH.Run(cmd, 0, true)
    

    As it can be noticed, in .Run() call, "WaitOnReturn" is set to "true" as I want to know when external program finishes and additionally it status

    Problem is that external program needs some time to finish and I want to pop "Please wait..." MsgBox but I can't this way as I set "WaitOnReturn" on "true" which I need as I need result from that program for additional processing

    Is there a way I can show somehow this MsgBox while external program is executed?

  • jpf
    jpf over 12 years
    No need to be embarrassed, we all have oversights. I considered pointing it out to you but thought that you didn't want to be dependent on clicking away the MsgBox before starting your command.