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?

link|improve this question

feedback

2 Answers

up vote 11 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

JR

link|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
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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