Scenario / Questions

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

Find below all possible solutions or suggestions for the above questions..

Suggestion: 1

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.

Suggestion: 2

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">
  <RegistrationInfo>
    <URI>reconnect vpn</URI>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <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>
    </EventTrigger>
    <EventTrigger>
      <Enabled>true</Enabled>
      <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>
    </EventTrigger>
  </Triggers>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\rasdial.exe</Command>
      <Arguments>"MyVPN Name" user password</Arguments>
    </Exec>
  </Actions>
</Task>

Suggestion: 3

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.