Connect to VPN from cmd.exe (vista)
Posted 24 February 2008 - 01:09 PM
i want to be able to start a connection and stop a vpn connection from cmd so i can use it in a batch file, however i can't find much on it and before i spend an hour looking through every inch of netsh and any other command that might work, i wandered if anyone knew how to do this? Before you suggest it making a shortcut to it and then calling that doesn't work.
This is so a batch file can:
Connect to VPN
Map a network drive that requires VPN access
Wait for request to close
Disconnect network drive
Dissconnect from VPN
Posted 17 March 2008 - 03:21 PM
ie rasdial "VPN NETWORK NAME" "Username" *
it will then prompt for a password, else you can use "username" "password", this is however less secure,
Posted 18 March 2008 - 03:28 AM
all i use is
rasdial "University Of York VPN" "%USER%" *
University Of York VPN is the exact name of my VPN connection which is already set up and working, and USER is pre-set and then it prompts me for a password. it failed for me everytime at username if i didn't include one as it seams if you save a password into the VPN connection, rasdial can't access those details when run from a command.
the output i get in command prompt from typing "rasdial "University Of York VPN" "%USER%" *"
Connecting to University Of York VPN...
Verifying username and password...
Registering your computer on the network...
Successfully connected to University Of York VPN.
Command completed successfully.
If you tell me more about what your doing and what it tells you i will try and help.
Posted 18 March 2008 - 11:06 AM
Posted 18 March 2008 - 11:36 AM
Well a little look into is shows that under vista the VPN data is stored under C:\Users\USERNAME\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk (Program data if its shared i guess) and XP C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\ (May also be in per user basis, dont use xp anymore so dont know).
I dont have time to try it atm, but this is my suggestion:
Include with your script rasphone.pbk, which would be created when you set up a vpn connection on the base machine
Then in your script,
Set working directory to a variable name so you can return to it
Move to the directory where the phonebook is stored using variable names based on the user profile (use cd /d LOCATION, as /d will change drive if needed)
(%APPDATA% will get you as far as Roaming under vista so %APPDATA%\Microsoft\Network\Connections\Pbk\, to see available variables type SET under cmd.exe)
test that the phone book is there, if it is, rename it to rasphone.pbk.bk, then xcopy from the script location (as saved in variable) the new phone book, to the new place,
when ready, disconnect, and overwrite the phone book with your settings in with the original file if is there, else simply delete the phone book.
[Editing the phonebook seamed to work without any problems]
Let me know how it goes
Posted 18 March 2008 - 12:59 PM
Then confirmed i couldn't connect
Then restored the phone book and the VPN connection re-appeared automatically under network connections although it lacked the username and password that i had saved for it previously, it was fully functional under rasdial where the username and password was specified which is what is required.
So see no reason why the method i described above wouldn't work correctly.
I assume by your Super Moderator status you have no problems writing batch scripts, however if you want a suggestion i will be happy to help.
Posted 18 March 2008 - 08:02 PM
- ← problem with gateway
- Networks and the Internet
- AtGuard Firewall user looking for new application →