执行时显示消息对话框

执行时显示消息对话框

本文介绍了执行时显示消息对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 vbscript 中使用这个片段:

I use this snippet in vbscript:

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

可以注意到,在 .Run() 调用中,WaitOnReturn"设置为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

问题是外部程序需要一些时间才能完成,我想弹出请稍候..."MsgBox 但我不能这样,因为我将WaitOnReturn"设置为true",因为我需要结果从该程序进行额外处理

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

有没有办法在执行外部程序时以某种方式显示这个 MsgBox?

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

推荐答案

抱歉,我突然想到我可以在执行之前调用 MsgBox Run():尴尬:

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

这里没有用户交互是一种解决方法(取自 http://www.robvanderwoude.com/vbstech_ui_progress.php)

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

然后调用它:

ProgressMsg "正在安装,请稍候.", "一些标题"

以以下方式结束:

ProgressMsg "", "一些标题"

这篇关于执行时显示消息对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 03:50