Configure Windows to Automatically connect to VPN

I recently had a need to setup a server that would automatically connect to VPN on Windows startup. On this remote site I did not have a router with VPN tunnel capability. You will need to perform 3 tasks.

1. Create the VPN connection

2. Write a batch file to connect to VPN

3. Create a scheduled task in Windows task scheduler that will kick off the batch file at Windows start up

Here are the steps in detail:

1. Create your VPN connection

I am not going to go through all the steps of creating a VPN connection in Windows. I assume that you would not be reading this post if you did not already know how to create a basic VPN connection. However there is a setting in the VPN connection that you will want to set. This setting is:

  • On the VPN connection Options tab set the Redialing options. Select Redial if the line is dropped. This will attempt to reconnect the VPN connection if it detects that it has lost the connection. This is helpful if the internet connection drops and comes back.

clip_image001

2. Create a VPN auto connect batch file.

It should consist of

cd C:\Windows\System32\

rasdial.exe “MY VPN” “DOMAINNAME\USERNAME” “PASSWORD

Replace “DOMAINNAME\USERNAME” “PASSWORD” with your own. Save this batch file on your %systemdrive%. When you are done you should have a AUTOVPN.bat file.

3. Setup the VPN auto connect task in Windows Task Scheduler

  • Open Windows Task Scheduler and create a scheduled task named “AUTOVPN” and give it a description. Select run whether user is logged on or not. Select Run with highest privileges then click on the Triggers tab.

clip_image002

  • On the Triggers tab and create a trigger for the task and select to Begin the task At startup from the dropdown.
  • Under Advanced settings chose to repeat the task on an interval that you are comfortable with. I chose every 15 minutes. Also set the duration to indefinitely.

clip_image003

  • Click on the Actions tab and click the New button to set an action. Set the action to start a program and in the Program/script field put the path to c:\AUTOVPN.bat the batch file you created in an earlier step.

clip_image004

  • On the Conditions tab un-select all conditions. These seem to cause conflicts with starting the task so you don’t want any of these.

clip_image005

  • All of the configurations on the Settings tab can be set to what you want. I do recommend enabling the If the task fails, restart every: option. This will retry launching the task if fails when starting.

clip_image006

Click ok and now your task should be set and your computer will connect to VPN automatically on startup of Windows.

2 comments to Configure Windows to Automatically connect to VPN

  • crocee  says:

    If you need to connect to a Virtual Private Network at windows startup, and you don’t want to have the user push connect or enter the password do the following:

    1) On the VPN Connect screen, check “Save this user name and password for the following users”
    2) Select the “Anyone who uses this computer” radio button
    3) Click “Properties” on the VPN Connect screen
    4) On the “Options” tab, uncheck:
    -“Display progress while connecting”
    -“Prompt for name and password, certificate,etc.”
    5) In Windows Explorer, browse to C:\Documents and Settings\All Users\Start Menu\Programs\Startup
    6) Open a new Windows Explorer and browse to Control Panel\Network Connections
    7) Drag the icon of your VPN connection to the Startup folder. This will create a shortcut

    Now at Windows startup, the VPN service will launch and connect silently.

  • jahandy  says:

    I searched for a way to keep a VPN connection alive and this was one of the first hits on Google.. so, I hope this helps you to keep a VPN connection alive.

    The premise to this being that the basic internet connection stays alive as well. (Since I use a cable router that connects to the internet I don’t know how to keep a dial-up connection alive via Windows, sorry.)

    windowsvpn.info/vpn-show.php?e_id=19

    This tutorial is really great.

    However, you need to change the entries in the “VPN Server List” file to match your VPN connection. Note that the default connection in the Server List File is set to “VPN-servername2”, so either you enter your VPN address in “VPN-servername2″ or you enter the address in”VPN-servername1” and change the default to “VPN-servername1” as well which makes more sense to me.

    If you’re just using 1 VPN connection with 1 static server address you may change the settings in step 8 and enter your VPN’s address in the field next to “Always use the same VPN server” and activate that toggle.

    Also, you may need to change the connection security settings to a different protocol, according to your VPN encryption (Step 12).

    Once done you need to start the executable the program generated and install the connection in Windows. You then get the old school xp dial-up window where you enter the username and password for your VPN connection. To enable auto-redial you need to save the password of course and check “connect automatically”.

    Also, by default the connection will disconnect after 10 minutes of idle time. To change that click on “Properties” in the dial-up window and set “Idle time before disconnecting” to “never”. Set the number of redial attempts to suit your needs too.

    That should be all. From now on your VPN is auto-redialed if the connection’s lost!

Leave a reply