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精确计算100的阶乘
  2. VB6拾遗:调用C函数(__cdecl调用约定)
  3. VBS中的左移位&右移位运算
  4. TiddlyWiki
  5. VBS获取文件的SDDL字符串

留下回复