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
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
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
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
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>
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 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.
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.