Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

Connect to VPN from cmd.exe (vista)

- - - - -

  • Please log in to reply
7 replies to this topic

#1
fairyprincess

fairyprincess

    Newbie

  • Member
  • 40 posts
  • OS:none specified
  • Country: Country Flag
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


How to remove advertisement from MSFN

#2
fairyprincess

fairyprincess

    Newbie

  • Member
  • 40 posts
  • OS:none specified
  • Country: Country Flag
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,

#3
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Super Moderator
  • 7,039 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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?

#4
fairyprincess

fairyprincess

    Newbie

  • Member
  • 40 posts
  • OS:none specified
  • Country: Country Flag
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.

#5
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Super Moderator
  • 7,039 posts
  • OS:Windows 7 x64
  • Country: Country Flag
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.

#6
fairyprincess

fairyprincess

    Newbie

  • Member
  • 40 posts
  • OS:none specified
  • Country: Country Flag
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

#7
fairyprincess

fairyprincess

    Newbie

  • Member
  • 40 posts
  • OS:none specified
  • Country: Country Flag
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.

#8
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Super Moderator
  • 7,039 posts
  • OS:Windows 7 x64
  • Country: Country Flag

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN