标题: 让它沉坛
[打印本页]
作者: hackhd
时间: 2008-4-2 07:42
标题: 让它沉坛
如题!
实现的效果就是。
如果已连接上互联网。那么 msgbox ("现在可以上网")如果没有连接上互联网那么等待,直到连接上互联网再 msgbox ("现在可以上网")
因为我用VBS实现的一个功能必须要连接上互联网才可以正常执行
考虑到某些ADSL用户,开机可能很慢。还没有等到用户拨上互联网我的VBS脚本就已经运行完并退出了。然而功能却并未实现.所以想加一个判断,等一等机器慢或拨号慢的用户
[ Last edited by hackhd on 2009-1-29 at 15:19 ]
作者: hackhd
时间: 2008-4-2 17:45
作者: luckboy45
时间: 2008-4-2 19:07
:start
ping 127.0.0.1 -n 10 >nul
ping
www.baidu.com -n 3 | find "Received = 1"
if errorlevel 1 goto start && goto next
:next
下面写入需要调用的VBS
保存为.BAT执行
作者: hackhd
时间: 2008-4-2 19:13
作者: hackhd
时间: 2008-4-2 20:39
网络连上的时候会弹出OK
没有连接上的话就会出错.
我要想连就弹OK.没连就等待,直到连上再弹OK.
要怎么弄.
[ Last edited by hackhd on 2009-1-29 at 15:19 ]
作者: slore
时间: 2008-4-2 23:34
Option Explicit
Dim strIP
MsgBox Ping("www.G.cn")
Function Ping(strIP)
Dim objPing, objRetStatus
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strIP & "'")
For Each objRetStatus In objPing
If IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode <> 0 Then
Ping = False
'WScript.Echo "Status code is " & objRetStatus.StatusCode
Else
Ping = True
'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
End If
Next
Set objPing = Nothing
End Function
作者: hackhd
时间: 2009-1-29 03:28
N久了,又翻出了这帖子,当初slore大哥给我回复我不知道。今天测试发现不管上网还是不上网都是弹出的 False
不过经我修改OK了
[ Last edited by hackhd on 2009-1-29 at 03:59 ]