cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4729
Views
0
Helpful
5
Replies

Using vpncli in scheduled tasks

rmenjivar1
Level 1
Level 1

Hi all,

I have a scheduled task that will execute a VBS file. This script will execute vpncli in a command line window and send the login username/password to this window. However, the task doesn't seem to execute properly. I confirm this when, after executing the scheduled task, I open a new command line window and check that connection status executing vpncli. How can I resolve this? Thanks.

-Rudy.

5 Replies 5

JP Miranda Z
Cisco Employee
Cisco Employee

Hi Rudy,

Can you share the VBS so we try to figure it out what is going wrong?

Hope this info helps!!

Rate if helps you!! 

-JP-

Below is the function subroutine I call: (please pardon the sleep lengths)

Sub VPN_open
  VPN_Profile = "vpn.myhost.com"
  VPN_User = "USERNAME"
  ' If the password contains special characters, enclose the characters in curly braces {}.
  VPN_Password = "PASSWORD"
 
  oShell.Run "cmd"
 
  WScript.Sleep 100
 
  oShell.AppActivate "C:\Windows\System32\cmd.exe"
 
  oShell.SendKeys "vpncli connect " & VPN_Profile & "~"
 
  WScript.Sleep 30000
 
  oShell.SendKeys VPN_User & "~"
 
  WScript.Sleep 15000
 
  oShell.SendKeys VPN_Password & "~"
 
  WScript.Sleep 15000
 
  oShell.SendKeys "exit~"
 
End Sub 'VPN_open

Thanks in advance.

Hi rmenjivar1,

I found a way to do it like this:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe"""
WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"
WScript.Sleep 3000
WshShell.SendKeys "connect " & VPN_Profile & "~"
WScript.Sleep 3000
WshShell.SendKeys VPN_User & "~"
WScript.Sleep 3000
WshShell.SendKeys VPN_Password & "~"
WScript.Sleep 3000

Hope this info helps!!

Rate if helps you!! 

-JP-

In addition,

I'm currently trying to run some of the commands manually and come across the following output when attempting the connection "vpncli connect vpn.myvpnsite.com":

      >> state: Disconnected
      >> state: Disconnected
      >> notice: Ready to connect.
  VPN>
      >> Searching for optimal server. Please wait...
      >>
      >> registered with local VPN subsystem.
      >> contacting host (vpn.myvpnsite.com) for login information...
      >> notice: Automatically selected server: vpn-1.myvpnsite.com
      >> Ready to connect.
      >>
And after the above output, it just hangs as if waiting for input, but it's unresponsive.

Thanks JP,

How should I go about making this a scheduled task? That's weird is that it seems to work whenever I execute my original code from the command line manually, but not when it's run as a scheduled task. I even select to run this task as "SYSTEM" with highest privilege.