fairyprincess Posted February 24, 2008 Posted February 24, 2008 Hi, 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 VPNMap a network drive that requires VPN accessWait for request to closeDisconnect network driveDissconnect from VPNThanks
fairyprincess Posted March 17, 2008 Author Posted March 17, 2008 Just incase anyone wanted to do this and finds this in the future, you can use rasdial.exe from command prompt to connect to a VPN networkie rasdial "VPN NETWORK NAME" "Username" *it will then prompt for a password, else you can use "username" "password", this is however less secure,
gamehead200 Posted March 18, 2008 Posted March 18, 2008 Hey fairyprincess,I'm actually looking into doing this myself but can't seem to get a connection with rasdial. Are there any other steps you took in getting it to work?
fairyprincess Posted March 18, 2008 Author Posted March 18, 2008 Um... where does it fail? What does it tell youall i use israsdial "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%" *"is: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.
gamehead200 Posted March 18, 2008 Posted March 18, 2008 Ah, I was under the impression that you did not have to create the VPN connection ahead of time. What I'd like to do is have a batch file run that connects to a VPN using specific credentials and then another batch file that disconnects it. The catch is that the VPN connection should not have to be setup ahead of time.
fairyprincess Posted March 18, 2008 Author Posted March 18, 2008 Hi, 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 machineThen in your script,Set working directory to a variable name so you can return to itMove 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,then connectwhen 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
fairyprincess Posted March 18, 2008 Author Posted March 18, 2008 Did a simple test of copying rasphone.pbk then deleting the VPN connection from network connections and deleting the phonebook. Then confirmed i couldn't connectThen 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.
gamehead200 Posted March 19, 2008 Posted March 19, 2008 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.Haha, you're correct. I will be trying this out when I have a chance. Busy with work and school at the moment.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now