On windows server 2008,2012 or above I need to re-connect VPN automatically once it is disconnected due to any reason.

It may be server restart, Manual command to Disconnect. Persistent VPN connection.

Any work arounds

5 Answers 5


I sort it out using "Task Scheduler"

Here are steps to do it

  1. Make VPN Connection and give it Some Name Let say "My VPN"

  2. Open "Task Scheduler" from Start Menu and click "Create Task" (Option can be found on right side of Task Scheduler)

  3. POPUP will appear asking for Task Information. Fill in information like below Task Info

  4. After that go to Trigger Tab and Select "New". Another POPup will appear like below New Trigger

  5. On Top Select "Begin The Task" Drop Down Menu and choose "On an Event"

  6. Below List will change In "Log:" Choose "Application", In "Source:" choose "RasClient", In "EventID:" choose "20226" and then click OK like below Event Trigger

  7. Again click on "New" and add another Trigger. On Top again Select "Begin The Task" Drop Down Menu and choose "On an Event" then In "Log:" Choose "Microsoft-Windows-NetworkProfile/Operational", In "Source:" choose "NetworkProfile", In "EventID:" choose "10000" and then click OK like below Network Trigger

  8. This will add two triggers for our Tasks. like below Triggers List

  9. Now we will Add action. Click on Next Tab named "Action" and then Click New, Another Popup will appear. In "Action:" it should be Start a Program then In "Program/Script:" Click Browse and Choose rasdial.exe Its path will appear as it is present inside "System32" folder.Now you need to add name of VPN and credentials in "Add arguments (optional)" in following order

    "VPN Name" username passwordAction

  10. Now click OK and Create Task It will appear Tasks List. Now go to VPN Connection Disconnect it and you will see it reconnects automatically. Restart the server and you will see VPN Connected By Default.

  • 3
    I developed a Windows service application to monitor the VPN and do this a few years back. I never thought of the task scheduler thing. I imagine this would be easy to push out with GPO also. Jan 18, 2018 at 4:35

In case you are lazy you can import this into the task scheduler. Just edit the action with your own vpn details and save as XML.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
    <URI>reconnect vpn</URI>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Application"&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='RasClient'] and EventID=20226]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-NetworkProfile/Operational"&gt;&lt;Select Path="Microsoft-Windows-NetworkProfile/Operational"&gt;*[System[Provider[@Name='NetworkProfile'] and EventID=10000]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
  <Actions Context="Author">
      <Arguments>"MyVPN Name" user password</Arguments>

I followed this answer but raspdial "MyVpn" user password started without delay cannot reestablish my connection. Solved it by using a 30 sec delay in task setting

Also with rasphone -d "MyVPN" you not exposing credentials in the task settings (enable "autosave credentials" in the VPN connection option). Just edit the action

Probably with the delay raspdial would also work fine.

  • very excellent. now I can cancel reconnecting if I don't want reconnection one time.
    – afruzan
    Jan 8 at 8:42
  • in my case, there was no need to delay.
    – afruzan
    Jan 8 at 8:43

If your VPN login/password are saved, you can use this little powershell script, that will log the VPN back when it's disconnected.


I have experienced this problem. I close all apps and reboot. I will get a green screen scan page for < I minute. In Control Panel>Networks>change adapter settings, I manually enable the main cable. After that all is well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .