Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In an XP Pro workstation, is there a way to start the native Windows VPN client and open/close a connection from the command line so it can be scripted in a batch file?

share|improve this question

4 Answers 4

up vote 23 down vote accepted

Yes, if the VPN connection is called "My VPN" then:

rasdial "My VPN"

will dial the connection. Helpfully it sets errorlevel to the RAS error code if it fails to connect, so your script can detect a connection failure. If you need to supply a username and password instead of using the saved credentials use:

rasdial "My VPN" username password

To disconnect a connection use:

rasdial "My VPN" /disconnect

JR

share|improve this answer
    
Thanks, this looks like it will do exactly what I need. –  nedm Jun 22 '09 at 7:20
1  
+1. This is exactly what I am looking for in my build automation scripts. A lot easier than I anticipated. –  joseph.ferris Oct 9 '09 at 17:03
    
FWIW, also works in Vista (as expected) –  daughtkom Jan 23 '10 at 14:48

An alternative that works under Windows 7 (not sure about XP) is:

rasphone -d "My VPN"

This brings up the "dialling" dialog, same as if you double-click on the connection. If you have the username and password saved it automatically dials.

rasdial did not work for me (on Windows 7):

Verifying username and password...

Remote Access error 691 - The remote connection was denied because the user name
 and password combination you provided is not recognized, or the selected authen
tication protocol is not permitted on the remote access server.

If you add empty strings under Windows 7 it works with cached credentials: rasdial "My VPN" "" "" (those are two pairs of double quotes with nothing in between)

share|improve this answer
    
I couldn't get rasdial to work on Windows 8.1 but this worked perfectly. +1 –  Smalltown2k May 3 at 16:54

:: run command-line: Control ncpa.cpl

enter image description here

:: Network Connections control

Network Connections control

:: first run edit My VPN Settings

enter image description here

:: after setup edit My VPN Settings

enter image description here

:: save cred

enter image description here

:: destination VPN host settings

enter image description here

:: silent VPN up settings!

enter image description here

:: VPN networking

enter image description here

:: VPN TCP advanced

enter image description here

:: VPN GW

enter image description here

:: Advanced network connection

enter image description here

:: Set priority interface

enter image description here

:: Set priority interface apply

enter image description here

:: Set priority network provider

enter image description here

:: Silent-dial.cmd

:: - comment in cmd) - REM alternative

:: disabled command output

@echo off

:: Silent dial "My VPN" @rasphone -d "My VPN"

:: wait 10 sec W2K3 server test

::@SET waitsec=10

::@choice /T %waitsec% /N /D y /M "wait %waitsec% sec"

:: wait 10 sec - alternative - XP .. 7

@ping 127.0.0.1 -n 10 > NUL

:: ************************

:: get path :: set route table :: run application

:: ************************

@ping 127.0.0.1 -n 10 > NUL

:: silent close "My VPN" connection

@rasphone -h "My VPN"

:: END Silent-dial.cmd

Use powershell or WSH ...

share|improve this answer
    
Please try to add descriptions to your code-only answers :) –  Adrian Lang Nov 23 '12 at 19:37

I have not seen a command line scheme for the client yet. But, that does not mean it cannot be automated in scripts. Here is a two step approach,

  • Create the shortcut link for the VPN as is done normally for your VPN users
    • Keep it configured with username and password
  • Use AutoIt to script only,
    • launching the shortcut, and
    • pressing ENTER on the VPN login window (which is what a user does when everything is configured)


If I recollect correctly, the code for pressing enter on a window is simply,

Send ("{ENTER}")

Look at the Send command.

You can setup AutoIt on one of your administration machines, get the script working, make and executable for it, and give it to the users. It can then be launched from command line as an executable.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.