如何在VB脚本中Ping IP
函数代码如下,通讯成功返回True,通讯失败返回False:
Function PingIP(IP) Dim objWMIService '定义SWbemServices对象 Dim colItems 'SWbem对象集合 Dim objItem 'Swbem单个对象 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_PingStatus Where Address='"& IP &"'") For Each objItem In colItems If objItem.StatusCode = 0 Then PingIP = True Else PingIP = False End If Next end Function
使用方式:
msgbox PingIP("172.16.15.23")
本文来自博客园,作者:星墨,转载请注明原文链接:https://www.cnblogs.com/yada/p/12071555.html