ping站点,如果脱机运行另一个vbs

问题描述 投票:1回答:2

我正在寻找一种通过VBScript ping主机名的方法,如果在经过几次错误计数后失败,如果脱机,它将运行另一个vbs文件。

[我有许多脚本可以通过VBScript ping主机,但是我不知道,我也无法找到ping主机的方法,如果不能ping通,则无法重定向并运行另一个VBScript。

我尝试在其中一个脚本的末尾添加以下内容:

如果strFailedPings =“”然后WScript.Echo“指定计算机的Ping状态正常”否则

((在此处放置代码以打开另一个vb)

实施例:

strComputers = "192.168.1.1,192.168.1.4"
arrComputers = Split(strComputers, ",")

For Each strComputer In arrComputers
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
        ExecQuery("SELECT * from Win32_PingStatus WHERE address = '" & _
        strComputer & "'")
    For Each objPingStatus In objPing
        If IsNull(objPingStatus.StatusCode) Or objPingStatus.StatusCode<>0 Then
            If strFailedPings <> "" Then strFailedPings = strFailedPings & vbCrLf
            strFailedPings = strFailedPings & strComputer
        End If
    Next
Next

If strFailedPings = "" Then
    WScript.Echo "Ping status of specified computers is OK"
Else
    WScript.Echo "Ping failed for the following computers:" & _
        vbCrLf & vbCrLf & strFailedPings
End If
vbscript ping
2个回答
1
投票

For循环中运行WMI查询n次,并对失败的ping进行计数和计数,如果失败计数超过给定的阈值,则运行另一个脚本。


0
投票

我认为您不能中断GetObject行:

© www.soinside.com 2019 - 2024. All rights reserved.