Home » Categories » Windows

Configure Windows to Automatically connect to VPN by Windows Task Scheduler

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.

Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments (1) Attachments
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
Windows VPN route selective traffic by destination network
Viewed 395 times since Tue, Dec 27, 2022
Where are the shortcuts for the Windows 7 Taskbar stored on disk?
Viewed 368 times since Tue, Jan 24, 2023
Reclaiming disk space from thin provisioned VMDK files on ESXi
Viewed 1888 times since Sun, Feb 27, 2022