Auto Reconnect VPN on Disconnection due to any reason - Persistent VPN
I sort it out using "Task Scheduler"
Here are steps to do it
Make VPN Connection and give it Some Name Let say "My VPN"
Open "Task Scheduler" from Start Menu and click "Create Task" (Option can be found on right side of Task Scheduler)
POPUP will appear asking for Task Information. Fill in information like below
After that go to Trigger Tab and Select "New". Another POPup will appear like below
On Top Select "Begin The Task" Drop Down Menu and choose "On an Event"
Below List will change In "Log:" Choose "Application", In "Source:" choose "RasClient", In "EventID:" choose "20226" and then click OK like below
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
This will add two triggers for our Tasks. like below
-
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 password
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.
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><QueryList><Query Id="0" Path="Application"><Select Path="Application">*[System[Provider[@Name='RasClient'] and EventID=20226]]</Select></Query></QueryList></Subscription>
</EventTrigger>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id="0" Path="Microsoft-Windows-NetworkProfile/Operational"><Select Path="Microsoft-Windows-NetworkProfile/Operational">*[System[Provider[@Name='NetworkProfile'] and EventID=10000]]</Select></Query></QueryList></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>