本帖最后由 yu2n 于 2015-4-27 16:54 编辑
- ' Ping 判断网络是否联通
- Function Ping(host)
- If CreateObject("WScript.Shell").Run("cmd /c ping -n 1 -w 500 " & host, 0, True) = 0 Then
- Ping = True
- Else
- Ping = False
- End If
- End Function
复制代码
- ' Ping 判断网络是否联通
- Function Ping(host)
- On Error Resume Next
- Ping=False : If (host="") Then Exit Function
- For Each o in GetObject("winmgmts:").ExecQuery _
- ("select * from Win32_PingStatus where address='" & host & "' and timeout=500")
- If (o.ResponseTime>=0) Then Ping=True : Exit For
- Next
- End Function
复制代码 用法:- If Ping("www.baidu.com") Then
- Msgbox "外网通。"
- Else
- Msgbox "外网不通。"
- End If
复制代码
|