如何在windows xp中检测到互联网连接后启动vbs脚本?
答
您可以启动一个VBScript,以查找来自Internet站点/设备/响应的任何响应。当它看到它,它会执行代码,否则它将尝试长达XX分钟并中止,例如:
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
答
您的应用程序可以简单地使用cscript.exe运行.vbs文件。例如
cscript.exe ScriptToLaunch.vbs
要检测互联网连接,您可以简单地使用某种'ping'命令。例如,请参阅VBS to check for active internet connection,并将其适用于...无论您正在使用哪种开发堆栈。
问题属于超级用户 – Ibu
您需要提供更多信息,如果您希望任何人帮助,卡洛斯。 – JohnZaj
问题对我来说似乎很清楚。如何在建立WiFi连接后自动执行VBScript。这个问题也可以说是关于编程,因为答案最终可能会显示出来。我通常是一个傲慢的SOB,关于不清楚的问题,但是这个问题完全公平(需要注意的是,它没有显示任何研究成果 - 但这不是一个容易找到的问题)。 –