r3nder
asked on
Connecting to VPN with a Batch file
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
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
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.
ASKER
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 . . .
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.
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.
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I clicked on submit too quickly. Note how I have the whole password in quotation.
ASKER
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
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
ASKER
It was a pleasure to have learned from you
No problem. I am glad I was able to help.