【问题标题】:Show Message dialog while executing执行时显示消息对话框
【发布时间】:2011-12-20 12:40:25
【问题描述】:

我在 vbscript 中使用了这个 sn-p:

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

可以注意到,在.Run() 调用中,“WaitOnReturn”设置为“true”,因为我想知道外部程序何时完成以及它的状态

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

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

【问题讨论】:

    标签: vbscript wsh


    【解决方案1】:

    对不起,它告诉我我可以在执行之前调用 MsgBox,Run() :尴尬:


    编辑:

    这里没有用户交互是一种解决方法(取自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 "Installing, Please wait.", "Some title"

    结束它:

    ProgressMsg "", "Some title"

    【讨论】:

    • 不用尴尬,我们都有疏忽。我考虑向您指出这一点,但认为您不想在开始命令之前依赖于单击 MsgBox。
    【解决方案2】:

    我在另一个博客上得到了答案,基本上,我所要做的就是全局调暗变量“ProgressMsg”。

    谢谢

    【讨论】:

      猜你喜欢
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      相关资源
      最近更新 更多