Jump to content

Automated VPN (Cisco AnyConnect) connection fails


Recommended Posts

Goals:

1. Start Cisco's AnyConnect VPN client.

2. Run a script

3. disconnect.

4. run reliably

I've been through a few iterations with this script. It works everytime I run it manually but something happens when I schedule the script and walk away. The script works for me in just a few lines but each time I've scheduled it, I find another thing that needs to be killed or activated or "waited" on. (As an explanation of all the extra junk around the essential statements)

Basic questions from a beginner:

Can you give me recommendations of how to stabilize this script?

Are there better functions to use to write the script?

Can you explain how to do some better error checking/recovery and logging?

Best regards,

Leo

;Make sure that no cli is already running
$list = ProcessList("vpncli.exe")
for $i = 1 to $list[0][0]
  ProcessClose( $list[1][1] )
Next


; Disconnect any already established session
ShellExecute("vpncli.exe ", " ",@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\","open" )
sleep(1000)
$activate_status = WinActivate(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("disconnect{enter}")
$activate_status = WinActivate(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("exit{enter}")
sleep(3000)
; if I am not dead yet, kill Me
WinKill(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")

; connect to vpn
ShellExecute("vpncli.exe ", " connect vpn.mysite.com ",@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\","open" )

sleep(3000)
$activate_status = WinActivate(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("userid{enter}")

sleep(2000)
$activate_status = WinActivate(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("password{enter}")

Sleep(8000)
ControlClick("Security Alert","","[CLASS:Button;INSTANCE:4]","primary")

sleep(5000)
WinKill(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")

;get data
RunWait("/ivc/tclscript.bat")


sleep(3000)
; Disconnect any already established session
ShellExecute("vpncli.exe ", " ",@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\","open" )
sleep(1000)
$activate_status = WinActivate(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("disconnect{enter}")
$activate_status = WinActivate(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
send("exit{enter}")
sleep(3000)
; if I am not dead yet, kill Me
WinKill(@ProgramFilesDir & "\Cisco\Cisco AnyConnect VPN Client\vpncli.exe")
Link to comment
Share on other sites

I don't see anything in your code to schedule the program to run. What are you using to autorun the file? Windows scheduler has quite a few problems.

I use something like

$timehour= inputbox('what hour? note, it is in 24 hour format')
$timemin= inputbox('what minute? 0-59 please')

while1
if $timehour=@hour then
  if $timemin=@min then

    run code
 
 endif
endif
sleep(10);prevents 100 cpu
wend
Link to comment
Share on other sites

Good suggestion; I'll just put it in your code and put it in the startup. (Yes I was using windows scheduler every 30 minutes)

I don't see anything in your code to schedule the program to run. What are you using to autorun the file? Windows scheduler has quite a few problems.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...