在 windows xp 中检测到互联网连接后如何启动 vbs 脚本? [英] How to launch vbs script after internet connection is detected in windows xp?

查看:66
本文介绍了在 windows xp 中检测到互联网连接后如何启动 vbs 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在建立 wifi 连接后启动 vbs 脚本?

How can i launch a vbs script after the wifi connection has been stablished?

提前致谢.

推荐答案

您可以启动一个 VBScript,它会循环查找来自 Internet 站点/设备/任何东西的响应.当它看到它时,它会执行代码,否则它会尝试最多 XX 分钟并中止,例如:

You could launch a VBScript that loops looking for a response from an internet site/device/whatever. When it sees it, it will execute code, otherwise it will try for up to XX minutes and abort, for example:

Const strTarget = "cnn.com"

startTime = Time
boolExitFlag = False

Do

    ' Check to see if I can get a ping response from target
    If Ping(strTarget) Then

        ' Call the code to run on connect
        Call runOnWIFI              
        boolExitFlag = True
    End If


    WScript.sleep 1000 ' Pause for 1 seconds before next attempt

    ' Stop trying after 5 minutes   
    If DateDiff("s", startTime, time) => 300 then boolExitFlag = True

Loop while boolExitFlag <> True



' * * * * * * * * * * * * * * * * * * * * * * * * * * * 
' Subroutine to run when WIFI connection is detected
' * * * * * * * * * * * * * * * * * * * * * * * * * * * 
Sub runOnWIFI

    ' INSERT CODE TO RUN ON WIFI CONNECTION HERE

End Sub



' * * * * * * * * * * * * * * * * * * * * * * * * * * * 
' Subroutine to see if the target machine is online
' * * * * * * * * * * * * * * * * * * * * * * * * * * * 
Function Ping(strHost)

    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & strHost & "'")

    z = 0
    Do    
        z = z + 1
        For Each objRetStatus In objPing        
            If IsNull(objRetStatus.StatusCode) Or objRetStatus.StatusCode <> 0 Then            
                PingStatus = False        
            Else
                PingStatus = True              
            End If      
        Next    

        ' Try a few times in case machine doesn't respond right away
        wscript.sleep 200
        If z = 4 Then Exit Do

    Loop until PingStatus = True

    If PingStatus = True Then 
        Ping = True
    Else
        Ping = False
    End If

End Function

这篇关于在 windows xp 中检测到互联网连接后如何启动 vbs 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆