vbs脚本实现Ping功能

将下列代码复制保存成txt文件,然后将文件的后缀即“xxx.txt”改成“xxx.vbs”即可

Dim WebAddress

WebAddress=InputBox("请输入你要ping的网络地址","ping a computer without using ping.exe","www.google.cn")
If WebAddress <> "" Then
Set OBJWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPings = OBJWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" &WebAddress& "'")
For Each OBJStatus in colPings
    If IsNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
        WScript.Echo "网址:" & WebAddress  & "无法连接,程序将退出!"
    Else
       call Main  
    End If
Next
End If

function Main()
   WScript.Echo "恭喜你,能够成功的ping通!"

end function


展开阅读全文

没有更多推荐了,返回首页