VPN client connect/disconnect via command line in XP

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?


Solution 1:

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

Solution 2:

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)