WMI中的Win32_PingStatus类

标签: , , , ,

平时很少用到ping命令,所以这个类也没怎么用过,测试了一下,好像效率比ping要高。计算ping 100次demon.tw延迟的平均值。

IP = "demon.tw"
WQL = "Select * from Win32_PingStatus Where Address = '$IP'"
WQL = Replace(WQL,"$IP",IP)
n = 0 : s = 0
Do Until n = 100
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery(WQL,,48)
    For Each objItem in colItems
        If objItem.StatusCode = 0 Then
            s = s + objItem.ResponseTime
            n = n + 1
        End If
    Next
Loop
WScript.Echo "Average:" & s / n

参考链接:Win32_PingStatus Class

随机文章:

  1. VBS打开选择文件对话框(Windows 7)
  2. WMI工具:Scriptomatic 2.0
  3. EditPlus注册机及其算法
  4. VBS加密 & VBE解密
  5. 全角空格?

留下回复