Jump to content

Connect to VPN from cmd.exe (vista)


Recommended Posts

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 VPN

Map a network drive that requires VPN access

Wait for request to close

Disconnect network drive

Dissconnect from VPN

Thanks

Link to comment
Share on other sites

  • 4 weeks later...

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 network

ie rasdial "VPN NETWORK NAME" "Username" *

it will then prompt for a password, else you can use "username" "password", this is however less secure,

Link to comment
Share on other sites

Um... where does it fail? What does it tell you

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%" *"

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

then connect

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :P I will be trying this out when I have a chance. Busy with work and school at the moment. :(

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...