Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- 'On Error Resume Next
- Dim i, WshShell, argv, pingTarget, password
- Set WshShell = WScript.CreateObject("WScript.Shell")
- Set argv = WScript.Arguments
- pingTarget = argv(0)
- password = argv(1)
- 'Keep looping back through the script so that it stays running
- i = 0
- Do While i = 0
- If ServerPing(pingTarget) Then
- 'Ping was successful
- Else
- 'Ping was not successful
- Call ReConnectVPN(WshShell, password)
- End If
- WScript.Sleep 10000
- Loop
- Function ReConnectVPN(WshShell, strPassword)
- WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"""
- WScript.Sleep 1000
- WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"
- WshShell.SendKeys "{TAB}"
- WshShell.SendKeys "{TAB}"
- WshShell.SendKeys "{ENTER}"
- WScript.Sleep 4000
- WshShell.SendKeys strPassword
- WshShell.SendKeys "{TAB}"
- WshShell.SendKeys "{ENTER}"
- WScript.Sleep 4000
- WshShell.SendKeys "{ENTER}"
- End Function
- '********************************************************************************
- 'ServerPing Function
- 'Ping the server and if available return true, otherwise false
- '********************************************************************************
- Function ServerPing(strServerName)
- Dim PINGFlag
- Set WSHShell = CreateObject("WScript.Shell")
- PINGFlag = Not CBool(WSHShell.Run("ping -n 5 " & strServerName, 0, True))
- If PINGFlag = True Then
- 'Ping was successful
- ServerPing = True
- Else
- 'Ping not successful
- ServerPing = False
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement