?
Solved

Connecting to VPN with a Batch file

Posted on 2010-09-18
9
Medium Priority
?
1,763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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 2000 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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
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…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 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