0

I am trying to make a batch script that automates login in and out of Cisco Anyconnect. I noticed that Anyconnect comes with a CLI application which should make this easy to do. However, my issue is that the CLI app requires me to provide input over multiple session. The flow is the following:

  1. First I type connect example.com and hit enter. Here example.com is the server I wish to connect to.
  2. Then I insert my username and hit enter.
  3. Lastly, I insert my password and hit enter.

I have read guides on how to pass multiple arguments to a batch script, but it seems that I need to do something extra in order for the arguments to be entered in accordance with the flow, i.e. the arguments should for instance be entered as if the return key is simulated. Is there someone with a suggestion?

misolsen
  • 3
  • 2
  • 1
    Have you already looked at a [SendKeys](https://stackoverflow.com/a/21273708/503046) solution? – vonPryz Nov 27 '18 at 06:54

2 Answers2

1

in batch, the following might work or might not work - depends on how connect is programmed:

(echo username&echo password)|connect example.com

Note: be careful with spaces ((echo username & echo password) might look better, but adds a space to the username (possibly making it an invalid username).

If your password should contain any poison chars, you have to escape them. (% with another%: %%, all others (<>&|) with a caret (for example ^&)

Stephan
  • 53,940
  • 10
  • 58
  • 91
0

If you know the inputs given interactively, you could try below in PowerShell.

'first input','second input','third input' | executable.exe

an example below.

'list disk','select disk 0','list partition' | diskpart.exe
Prasoon Karunan V
  • 2,916
  • 2
  • 12
  • 26