我正在多台计算机上运行基于网络的幻灯片。我有一个在启动时运行的 VBScript,打开 IE 并以全屏模式导航到特定页面。只要在启动时有互联网连接,一切都很好。如果没有,则页面永远不会加载。在 VBScript 中有没有办法每隔几分钟检查一次连接,直到找到连接,然后继续执行脚本?这是供您引用的代码:

Option Explicit
Dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next
   With WScript.CreateObject ("InternetExplorer.Application")
      .Navigate "http://www.example.com/slideshow"
      .fullscreen = 1
      .Visible    = 1
      WScript.Sleep 10000
   End With
On Error Goto 0

最佳答案

引用这个 ==> Loop a function?

是的,您可以使用以下代码轻松完成:

Option Explicit
Dim MyLoop,strComputer,objPing,objStatus
MyLoop = True
While MyLoop = True
    strComputer = "smtp.gmail.com"
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery _
    ("select * from Win32_PingStatus where address = '" & strComputer & "'")
    For Each objStatus in objPing
        If objStatus.Statuscode = 0 Then
            MyLoop = False
            Call MyProgram()
            wscript.quit
        End If
    Next
    Pause(10) 'To sleep for 10 secondes
Wend
'**********************************************************************************************
 Sub Pause(NSeconds)
    Wscript.Sleep(NSeconds*1000)
 End Sub
'**********************************************************************************************
Sub MyProgram()
Dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
   With WScript.CreateObject ("InternetExplorer.Application")
      .Navigate "http://www.example.com/slideshow"
      .fullscreen = 1
      .Visible    = 1
      WScript.Sleep 10000
   End With
On Error Goto 0
End Sub
'**********************************************************************************************

关于vbscript - 使用 VBScript 检查网络连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31028355/

10-13 02:59