do
Dim strMachines,aMachines,machine
Dim objPing,objStatus,objws '测试网络是否连接
Dim connect,unconnect
x=false
Machine="xx.xx.xx.xx"
Do
Set objPing=GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & machine & "'")
connect=0
unconnect=0
For i=1 To 10
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
unconnect=unconnect+1
connect=0
End If
Next
Next
If connect=10 Then
Set objPing=nothing
exit do
End If
Loop
set wshshell=wscript.createobject("wscript.shell")
x=timer
'测试网络是否断开
x=false
Machine="xx.xx.xx.xx"
Do
Set objPing=GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & machine & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
x=true
End If
Next
If x=true then
exit do
End If
Loop
y=timer
z=eval(y-x)
h=int(z\60*60*1000)
z=z mod 60*1000
m=int(z\60*1000)
z=z mod 1000
if h<>"0" then
msgbox "此次上网用时:"&h&"时"&m&"分"&z&"秒"
esle if m<>"0" then
msgbox "此次上网用时:"&m&"分"&z&"秒"
esle msgbox "此次上网用时:"&z&"秒"
end if
loop
'xx.xx.xx.xx是你的IP。
'当你的网络连接时就开始计时。误差单位是毫秒