# Solved: Batch file for VPN Logging.



## vane0326 (May 8, 2006)

Hi,

I would like to use a batch file that will launch my Cisco vpn Client and automatically log me in. I found this command line but I can't get it to work. Am I missing something.


```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe" -c -sd -user <username> -pwd <password> <connectionprofile>
```


----------



## TheOutcaste (Aug 8, 2007)

Are you specifying the complete path to the Connection profile? If not, you may have to first change the working directory to the folder that contains the profiles. using CD or PushD.
What errors do you get when you type that line into a Command Prompt?
Do you get the same errors when run in a batch file? (run the batch file from a Command PRompt, so the window won't close before you can read any errors.)


----------



## vane0326 (May 8, 2006)

This may sound weird but what does "connectionprofile" means? What should I put there?


----------



## TheOutcaste (Aug 8, 2007)

<connectionprofile> is the same as Connection Entry. You have to type the name of the Connection Entry that you want to use to connect with. If you don't type a name, it will use the default entry.
Like *Corp_Office*, *NewYorkOffice*, *ParisOffice*, etc
These should have a .PCF extension, but you don't need to type the extension.
Probably need to change to the client folder first:

```
CD /D "C:\Program Files\Cisco Systems\VPN Client"
vpngui.exe -c -sd -user vane0326 -pwd mypassword Corp_Office
```
The Administration Guides should have all this info. IF you don't have them on your PC, they can be found online at Ciscos Website:
Using the VPN Client Command-Line Interface

The vpngui.exe command is mentioned in this one.
Troubleshooting and Programmer Notes


----------



## vane0326 (May 8, 2006)

Thank you so much TheOutcaste!

I got it to work.

But there is another problem. When I run the batch file it does log me in but it ask me to continue. So I have to hit the Enter key to proceed.

Is there a command line or a send key we can put into the code*?*


----------



## TheOutcaste (Aug 8, 2007)

First thing that came to mind is you might have a *Pause* statement in the batch file. That will display *Press any key to continue . . .* in the Command Prompt window when it is executed.

If the prompt is comming from the VPN Client, try changing the */C* switch to */SC*.
It's not documented separately, but is mentioned in the description for other switches. Hopefully is works like the */SD* switch, the S meaning Silent, so no prompts are displayed.


----------



## vane0326 (May 8, 2006)

TheOutcaste said:


> First thing that came to mind is you might have a *Pause* statement in the batch file. That will display *Press any key to continue . . .* in the Command Prompt window when it is executed.
> 
> If the prompt is comming from the VPN Client, try changing the */C* switch to */SC*.
> It's not documented separately, but is mentioned in the description for other switches. Hopefully is works like the */SD* switch, the S meaning Silent, so no prompts are displayed.


I changed the "-c" to "-sc". It did not work.

It only suppressed the vpn gui BUT not the cisco banner. Look at the attachment below. Thats what comes up.


----------



## vane0326 (May 8, 2006)

I found this link below.

http://www.velocityreviews.com/foru...-using-command-line-to-cisco-vpn-3-6-3-a.html

The banner comes from the firewall it self so there's nothing we can do in our end.

Thank you for helping me though.


----------



## TheOutcaste (Aug 8, 2007)

Found that too, so has to be done on your end. Possible, but a bit involved.

Batch files can't send keys to a GUI program. best you can do is use a VBScript with AppActivate and SendKeys, but there are some problems using those methods. SendKeys sends keystrokes to the Active window, so if the current focus is not in the correct window, this can cause problems.
AppActivate searches for a window with a specified title and shifts the focus to it. It searches for an exact match, but if it doesn't find one, it starts looking for a window whose title starts with the specified title. If that fails, it looks for one that ends with it.

From the screen shot it's not clear how many spaces are between *Client* and the *|*. It looks like more than one, but can't tell if it's 2 or 3 or more, so some experimenting may be in order. And it's possible the pipe symbol (*|*) in the title won't match what the Command Prompt/VBS uses, so may have to just use *VPN Client* with the correct number of spaces, or at least more than one to reduce the chance of matching the wrong window.
Only reason to check that is if you happen to have another window open with a title that starts with VPN Client, say the web page for the VPN Client Administration guide. In that case, the wrong window could be activated.

I've written a little script that may help determine how many spaces there are.
Copy the text in the following code block into Notepad.
Save it on the desktop as *check.cmd*. Be sure to change the *Save as Type:* box to *All Files* when saving.

```
[plain](Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.strTitle1 = "VPN Client"
Echo.strTitle2 = "|"
Echo.strSpace = " "
Echo.varCount = 1
Echo.Do
Echo.varCurrent = 0
Echo.strTest = strTitle1
Echo.Do
Echo.strTest = strTest ^& strSpace
Echo.varCurrent = varCurrent + 1
Echo.Loop While varCurrent ^< varCount
Echo.strTest = strTest ^& strTitle2
Echo.WScript.Echo "Testing " ^& strTest
Echo.WScript.Sleep 10
Echo.check = objShell.AppActivate^(strTest^)
Echo.If check = True Then Exit Do
Echo.VarCount = VarCount + 1
Echo.Loop While varCount ^< 10
Echo.If varCount ^< 10 Then
Echo.MsgBox^("Number of spaces is " ^& varCount^)
Echo.Else
Echo.MsgBox^("Unable to find window. Make sure it is present"^)
Echo.End If)>"%temp%\Check.vbs"
cscript //nologo "%temp%\Check.vbs"
Del "%temp%\Check.vbs"[/plain]
```
Start the VPN client so that the banner dialog is displayed, then double click the *check.cmd* file to run it. Hopefully it will display a message with the number of spaces between *Client* and *|*. This looks to be the same as between *|* and *Banner*

Once we know the number of spaces, we can add this code to find the window and send ALT+C which will press the continue button for you.

```
:: Set this to the time in seconds to wait for the VPN Client Banner dialog to appear
Set _WaitTime=10
[COLOR=Red]:: Adjust spaces as needed[/COLOR]
Set _Title=VPN Client  |  Banner
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.VarCount = VarCount + 1
Echo.If VarCount = constWaitTime Then Exit Do
Echo.Loop While check = 0
Echo.If varCount = constWaitTime Then
Echo.MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.Else
Echo.objShell.SendKeys "%%C"
Echo.End If
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
```
What this does is create a temp VBS file in the temp folder. It checks for the VPN Banner window. When it's found, it sends the ALT+C to press continue and then deletes the temp VBS file.
If the window isn't found within 10 seconds (or whatever time you set) it displays an error, then deletes the temp VBS file.

Of course, if they change the window tile this will stop working, so would have to be changed to match the mew title.


----------



## vane0326 (May 8, 2006)

I ran the *Check.cmd* and it found *2* spaces.

So in the other code I put the number 2 and combinde the cisco code and the send code and nonthing happened. Did I do this right*?*


```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>

:: Set this to the time in seconds to wait for the VPN Client Banner dialog to appear
Set _WaitTime=10
:: 2
Set _Title=VPN Client  |  Banner
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.VarCount = VarCount + 1
Echo.If VarCount = constWaitTime Then Exit Do
Echo.Loop While check = 0
Echo.If varCount = constWaitTime Then
Echo.MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.Else
Echo.objShell.SendKeys "%%{LEFT}"
Echo.End If
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
```
Also, I found an interesting topic dealing with send keys. Please look at the link below and see if we can you use it

http://www.petri.co.il/forums/showthread.php?t=19983&highlight=send+key

Thanks!


----------



## TheOutcaste (Aug 8, 2007)

Opps, I've got the wrong SendKeys line in there, it's sending *ALT+Left Arrow *instead of *ALT+C*. I was using that in my testing to do a "back" button in a browser. Must have re-pasted it after I edited it. I corrected it in the previous post, it's the line with *%%{LEFT}* - that should be *%%C*

You need to set the number of spaces between *VPN Client* and *|* and between *|* and *Banner* in this line, rather than change the comment just before it:

```
Set _Title=VPN Client  |  Banner
```
So the title is *VPN{space}Client{space}{space}|**{space}{space}**Banner*
It was already set to two spaces so it should work. Since you didn't get the *Unable to find VPN Client Banner* error message, it's probably working, just was sending the wrong keys.

I would put all of this before the *vpngui* line, just so it's running before the *vpngui* command is executed, but as long as the banner appears within 10 seconds it shouldn't matter.
Give this a try:

```
:: Set this to the time in seconds to wait for the VPN Client Banner dialog to appear
Set _WaitTime=10
:: Adjust spaces as needed
Set _Title=VPN Client  |  Banner
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.VarCount = VarCount + 1
Echo.If VarCount = constWaitTime Then Exit Do
Echo.Loop While check = 0
Echo.If varCount = constWaitTime Then
Echo.MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.Else
Echo.objShell.SendKeys "%%C"
Echo.End If
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
```
Thanks for the link, some good info in there.
As the dialog doesn't have minimize and maximize buttons, I'm don't think accessing the Control Menu to maximize the window would be needed. You'ld have to hid the Show Desktop icon or use the Control Menu to hide the Banner dialog, so you'd have to be very quick.
Using the AppActivate method in the loop condition, or in the If condition rather than assigning the result to a variable and checking the variable might be a good idea. Here's a version using that method:

```
:: Set this to the time in seconds to wait for the VPN Client Banner dialog to appear
Set _WaitTime=10
:: Adjust spaces as needed
Set _Title=VPN Client  |  Banner
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.VarCount = VarCount + 1
Echo.If VarCount = constWaitTime Then Exit Do
Echo.Loop While objShell.AppActivate^("%_Title%"^) = False
Echo.If varCount = constWaitTime Then
Echo.MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.Else
Echo.If objShell.AppActivate^("%_Title%"^) = True objShell.SendKeys "%%C"
Echo.End If
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
```


----------



## vane0326 (May 8, 2006)

Hi TheOutcaste,

I really appreciate the time and effort you're helping me on this. So Thank you!!

Ok, I tried this code below and it did not work. I tried to launch it as a batch file and nothing happen.

So I pasted it into a command window. I waited until the error message prompt up saying...

* "Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"*

So I hit ok and then the VPN banner pops up. I then changed the time to 20 seconds and the same thing. The error pops up and soon as I hit the OK on the error box the VPN Banner appears. So no matter what time I changed the VPN banner appears after I hit ok on the error box.


```
:: Set this to the time in seconds to wait for the VPN Client Banner dialog to appear
Set _WaitTime=10
:: Adjust spaces as needed
Set _Title=VPN Client  |  Banner
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.VarCount = VarCount + 1
Echo.If VarCount = constWaitTime Then Exit Do
Echo.Loop While check = 0
Echo.If varCount = constWaitTime Then
Echo.MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.Else
Echo.objShell.SendKeys "%%C"
Echo.End If
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
```
Then I tried to put the VPN client exe line ontop of the code to see what would happen.

When I execute the code below the VPN Banner pops up so I waited and the error box pops behind the vpn banner saying...

* "Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"*


```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
:: Set this to the time in seconds to wait for the VPN Client Banner dialog to appear
Set _WaitTime=10
:: Adjust spaces as needed
Set _Title=VPN Client  |  Banner
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.VarCount = VarCount + 1
Echo.If VarCount = constWaitTime Then Exit Do
Echo.Loop While check = 0
Echo.If varCount = constWaitTime Then
Echo.MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.Else
Echo.objShell.SendKeys "%%C"
Echo.End If
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
```
What do you think might be going on*?*


----------



## TheOutcaste (Aug 8, 2007)

Sounds like it does have to have the VPN Client command first, it's apparently waiting for the script to finish before it's running the command. Adding *Start ""* to the line that starts with *cscript* might help on that, though it doesn't really matter which is first. So just leave the vpngui.exe command at the start of the file.

It sounds like it's not recognizing the Title for whatever reason. The *check.cmd* file can see it, so we know it's possible.

I'd check the *Set _Title* line. One extra space will make it fail, say if there is a space after *Banner*.
Try using just *Set _Title=VPN Client |*, or remove the *|* symbol and leave two spaces on the end, or try just *VPN Client*


----------



## vane0326 (May 8, 2006)

I tried your suggestions and it did not work. I left you a screen capture after running the check.cmd. Maybe it might give you a clue what it's giving us. Can we use a wildcard or something in the *Set _Title line*?


----------



## TheOutcaste (Aug 8, 2007)

OK, the check.cmd file uses *If check = True* to exit the loop when it finds the title. The actual file you are using does this differently, it loops while check = 0, which should be the same (0=False, -1=True) but seems it's not for some reason. Let's try checking the same way the *check.cmd* file does:

```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
:: Set this to the time in seconds to wait for the VPN Client Banner dialog to appear
Set _WaitTime=10
:: Adjust spaces as needed
Set _Title=VPN Client  |  Banner
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.If check = True Then Exit Do
Echo.VarCount = VarCount + 1
Echo.Loop While varCount ^< constWaitTime
Echo.If varCount = constWaitTime Then
Echo.MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.Else
Echo.objShell.SendKeys "%%C"
Echo.End If
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
```


----------



## vane0326 (May 8, 2006)

The Cisco VPN Banner pops up but nothing happened.

I even tried creating a text called enter.txt, I hit the enter key and saved the file on my c drive. Then in the command I redirect it. Well that didn't work either.

example:


```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile> <c:\enter.txt
```


----------



## TheOutcaste (Aug 8, 2007)

So, no error about the windows not beng found? Progress at least.

So it's finding the window. So down to something with send keys not working.
Try changing the sendkeys line to just send an enter key instead of ALT+C, thay may work better
Change this:
*Echo.objShell.SendKeys "%%C"*
to this:
*Echo.objShell.SendKeys "{ENTER}"*


----------



## vane0326 (May 8, 2006)

It did not work. I tried this as well.

*Echo.objShell.SendKeys "~"*

Still nothing.

Maybe there's another way. Instead of the code looking for the VPN banner can it just send command for the Enter key.

Because when I just launch the command line


```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
```
Then banner prompts up and all I have to do is just hit the enter key.

Can we somehow put a timer for the redirection and see if that works.

Example,


```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
Sleep (1000)<c:\enter.txt
```
I can't it to work.


----------



## TheOutcaste (Aug 8, 2007)

The "Enter" from the redirection will go to the Command Prompt, not the Banner window. The Command Prompt can't send keystrokes to a GUI window, only to itself.

I don't know why it's not working. It seems that AppActivate is now seeing the window, but the sendkeys part is not working, or not being seen.
Slightly different version that does the send keys from inside the loop, as soon as check goes true, see if that makes a difference.

```
Set _WaitTime=10
:: Adjust spaces as needed
Set _Title=VPN Client
Set /A _WaitTime=_WaitTime*10
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.If check = True Then 
Echo.objShell.SendKeys "{ENTER}"
Echo.Exit Do
Echo.End If
Echo.VarCount = VarCount + 1
Echo.Loop While varCount ^< constWaitTime
Echo.If varCount = constWaitTime Then MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
cscript //nologo "%Temp%\~Temp.vbs"
```
Can always test with a separate VBScript file. Save this on the desktop with a .vbs extension, when the banner appears, double click it to see if it will send the "Enter" keystroke to the Banner Window.

```
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
constWaitTime = 100
VarCount = 0
Do
WScript.Sleep 100
check = objShell.AppActivate("VPN Client")
If check = True Then 
objShell.SendKeys "{ENTER}"
Exit Do
End If
VarCount = VarCount + 1
Loop While varCount < constWaitTime
```


----------



## vane0326 (May 8, 2006)

TheOutcaste said:


> Can always test with a separate VBScript file. Save this on the desktop with a .vbs extension, when the banner appears, double click it to see if it will send the "Enter" keystroke to the Banner Window.
> 
> ```
> Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
> ...


This worked!!!

Is there a way to combined the scripts?

I tried...


```
Call c:\enter.vbs
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
```
Also I tried...


```
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
Call c:\enter.vbs
```
None of them worked.

Instead of using a batch file connecting the Cisco VPN How about using a VBScript file*?*


----------



## TheOutcaste (Aug 8, 2007)

OK, could be the script is seeing the Banner window title and sending the keystroke before the window is ready to receive it.
Let's try adding a delay before the SendKey line.
Try different values for the line in red, 1000 is one second:

```
Set _WaitTime=10
:: Adjust spaces as needed
Set _Title=VPN Client
Set /A _WaitTime=_WaitTime*10
:: Create VBS Script
(Echo.Set objFSO = WScript.CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objShell = WScript.CreateObject^("WScript.Shell"^)
Echo.constWaitTime = %_WaitTime%
Echo.VarCount = 0
Echo.Do
Echo.WScript.Sleep 100
Echo.check = objShell.AppActivate^("%_Title%"^)
Echo.If check = True Then
Echo.[COLOR=Red]WScript.Sleep 1000[/COLOR]
Echo.objShell.SendKeys "{ENTER}"
Echo.Exit Do
Echo.End If
Echo.VarCount = VarCount + 1
Echo.Loop While varCount ^< constWaitTime
Echo.If varCount = constWaitTime Then MsgBox^("Unable to find VPN Client Banner. You may need to increase the value of the _WaitTime variable"^)
Echo.objFSO.DeleteFile WScript.ScriptFullName)>"%Temp%\~Temp.vbs"
::::::::::::::::::::::::::::::::::::::::::::::::
:: Run Program and script
"C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"  -sc -sd -user  <username> -pwd <password> <connectionprofile>
cscript //nologo "%Temp%\~Temp.vbs"
```
This might work as a VBS only method. Getting the strCommand setup may take some tweaking as the paths have spaces. You have to use three double quotes wherever you need a single double quote, and use & to join the pieces together.
Might be easier to specify the command line in the Run command rather than using the strCommand variable, so if you keep getting erros that it can't find the file we can try that.
This also has a one second delay before the SendKeys line

```
intWindowStyle = 1
bWaitOnReturn = False
strCommand = """C:\Program Files\Cisco Systems\VPN Client\vpngui.exe""" & " -sc -sd -user  <username> -pwd <password> " & """<connectionprofile>"""
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
Return = objShell.Run(strCommand, intWindowStyle, bWaitOnReturn)
constWaitTime = 100
VarCount = 0
Do
WScript.Sleep 100
check = objShell.AppActivate("VPN Client")
If check = True Then 
[COLOR=Red]WScript.Sleep 1000[/COLOR]
objShell.SendKeys "{ENTER}"
Exit Do
End If
VarCount = VarCount + 1
Loop While varCount < constWaitTime
```


----------



## vane0326 (May 8, 2006)

TheOutcaste said:


> This might work as a VBS only method. Getting the strCommand setup may take some tweaking as the paths have spaces. You have to use three double quotes wherever you need a single double quote, and use & to join the pieces together.
> Might be easier to specify the command line in the Run command rather than using the strCommand variable, so if you keep getting erros that it can't find the file we can try that.
> This also has a one second delay before the SendKeys line
> 
> ...


VBS Script Worked!!!!!!!!!!!!!!!!!!!

Thank you so much for your time and effort on this.

I tried the batch file and still it did not work.

Maybe DOS is not as advance as VBS. Luckily VBS is native to windows.

I'm still curious why the batch file is not working though. But oh well.

Once again thank you!


----------



## TheOutcaste (Aug 8, 2007)

Cool, glad it worked. Don't know why the batch won't work either, probably something simple but obscure.

If your issue has been resolved you (and ONLY you) can mark this thread Solved by using the Mark Solved button at the Top Left of this thread (above the first post) 










Jerry


----------

