Solved

Connecting to VPN with a Batch file

Posted on 2010-09-18
9
1,667 Views
Last Modified: 2012-08-14
I have a batch file that I am passing parameters - it sets the username and password but the IKE connection fails - can someone check my batch file and tell me if it is correct?  also how can I tell what the value of the args are that are being passed to the console
any help would be greatly appreciated
@echo off

pushd "%programfiles%\checkpoint\securemote\bin"

if not exist scc.exe goto scc_missing

echo #### Setting command-line mode

scc.exe setmode cli

echo #### Setting login information


scc.exe userpass Username Password


echo #### Starting VPN connection

scc.exe connect -p Work

echo -

echo #### Testing connection

ping -w 1000 -n 4 10.10.0.18 > NUL

if errorlevel 1 echo Connection test failed!

if errorlevel 1 goto disconnect

if errorlevel 0 echo Connection tested OK!

:disconnect

echo -

echo #### Disconnecting..

scc.exe disconnect -p

echo #### Erasing login information

scc.exe erasecreds

echo #### Setting GUI (connect) mode

scc.exe setmode con

goto end

 

:scc_missing

echo #### SCC.EXE appears to be missing! Aborting..

goto end

 

:end

popd

echo #### Done!

pause

Open in new window

0
Comment
Question by:r3nder
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:sosinc3
ID: 33710288
If you want to see what is happening during the running of this batch file either remove the first @ECHO OFF line or put REM (with a space after it) at the beginning of that line. That way you can see each line as it is getting processed. Also, you could insert several PAUSE commands throughout your batch file to make the process stop to see where it exactly is failing.
0
 
LVL 6

Author Comment

by:r3nder
ID: 33710317
This is what I get: - Is it saying the word Username and password were set or the username and password args were set

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Setting command-line mode
#### Setting command-line mode

C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe setmode cli
Switched successfully to Command Line mode

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Setting login information
#### Setting login information

C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe userpass YOURLOGIN YOURPASSWO
RD
Username, password were set.

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Starting VPN connection
#### Starting VPN connection

C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe connect -p ETIHome
   Checking network connectivity...
   Preparing connection...
   Connecting to gateway...
   IKE negotiation failed
   Connection failed
Connect failed

C:\Program Files\CheckPoint\SecuRemote\bin>echo -
-

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Testing connection
#### Testing connection

C:\Program Files\CheckPoint\SecuRemote\bin>ping -w 1000 -n 4 10.10.0.18  1>NUL

C:\Program Files\CheckPoint\SecuRemote\bin>if errorlevel 1 echo Connection test
failed!
Connection test failed!

C:\Program Files\CheckPoint\SecuRemote\bin>if errorlevel 1 goto disconnect

C:\Program Files\CheckPoint\SecuRemote\bin>echo -
-

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Disconnecting..
#### Disconnecting..

C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe disconnect -p
Already disconnected

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Erasing login information
#### Erasing login information

C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe erasecreds
Credentials were unset OK.

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Setting GUI (connect) mode

#### Setting GUI (connect) mode

C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe setmode con
Switched successfully to Connect mode

C:\Program Files\CheckPoint\SecuRemote\bin>goto end

C:\Program Files\CheckPoint\SecuRemote\bin>popd

C:\Documents and Settings\Michael\My Documents\Visual Studio 2008\Projects\VPNTe
st\VPNTest\bin\Debug>echo #### Done!
#### Done!

C:\Documents and Settings\Michael\My Documents\Visual Studio 2008\Projects\VPNTe
st\VPNTest\bin\Debug>pause
Press any key to continue . . .

Open in new window

0
 
LVL 5

Expert Comment

by:sosinc3
ID: 33711452
In your batch file, you need to actually put the real username and the password so the line that now reads

SCC.EXE USERPASS YOURLOGIN YOURPASSWORD should be for example

SCC.EXE USERPASS sosinc3 secretpassword    assuming the username name was sosinc3 and the password was secretpassword.

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 6

Author Comment

by:r3nder
ID: 33711533
Yeah I figured how to pass that in last night - I used SCC.EXE USERPASS  Username= %1 password=%2
That passed the arguments to the batch file - now I have another problem - our company allows users to use special characters in their password. So I have to figure a way to pass the password with the special character as a set string. For example
Set Caret= ^^  
if Password=%2 = "^" set "^"
Not sure how to do it but - I am still looking
0
 
LVL 5

Accepted Solution

by:
sosinc3 earned 500 total points
ID: 33711649
just replace the line to read as follows:

SCC.EXE USERPASS %1 %2

Then when you run the batch file, lets assume it is called vpn.bat, you would type

vpn sosinc3 "secret$password&ofthe^day"

That works for me on my PC here.

0
 
LVL 5

Expert Comment

by:sosinc3
ID: 33711666
I clicked on submit too quickly. Note how I have the whole password in quotation.
0
 
LVL 6

Author Comment

by:r3nder
ID: 33712225
yes that worked - so what I am doing is in the windows form - I get the username and password - then when I pass the args from the form to the bat file I added
string args = @"/c VPN.bat " + Username + " " + '"'+ Password + '"';
and TADA! ......it worked - I guess I can leave it like that and no matter what is typed - So in password it will be sent using the double quotes
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 33712357
It was a pleasure to have learned from you
0
 
LVL 5

Expert Comment

by:sosinc3
ID: 33712707
No problem. I am glad I was able to help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question