By default, the built-in Windows VPN client does not attempt to reconnect to the VPN server if the connection is lost. If the connection is dropped, the user must manually reconnect to the VPN server. Windows has several tools that you can use to set up automatic VPN reconnection after a connection loss.
Reconnect settings are missing from the Windows VPN client GUI. However, you can configure them using the rasphone.pbk configuration file stored in the user profile (
%userprofile%\AppData\Roaming\Microsoft\Network\Connections\Pbk). The settings of all user VPN connection profiles are stored in this file.
Open the rasphone.pbk file with a text editor, look for the section of the VPN profile you want to use (for example [L2TP-VPN]), and scroll down to the following options:
- RedialAttempts=3 – number of reconnect attempts (maximum 99)
- RedialSeconds=60 – seconds between reconnect attempts
- IdleDisconnectSeconds=0 — the waiting time before it becomes clear that a connection has been lost (0 –don’t wait)
- RedialOnLinkFailure=1 — redial if the connection fails (1 – yes, 0 – no)
However, the rasphone.pbk settings may not work correctly in all cases. It is therefore recommended that you automate VPN reconnection using a scheduler task that reconnects to the VPN when the connection is lost or when the computer is connected to the network (Wi-Fi or Ethernet). We are interested in the following events
|20226||RasClient (Application log)|
|10000||NetworkProfile (Microsoft-Windows-NetworkProfile/Operational log)|
Open Windows Task Scheduler (
taskschd.msc) and create a new task. Set a task name: AutoReconnectVPN.
Go to the Triggers tab and create two event triggers (Begin the task: On event):
Now you need to configure the action to be taken when one of these events occurs. Go to the Actions tabs -> click New.
- Action: Start a program
In this example, a VPN profile with a saved password is used for the connection. To explicitly specify the VPN connection name and password, set them as follows:
"YourVPNCOnnectionName" username password
Test the scheduler task: temporarily unplug the network cable from the computer, disable the network adapter, or disconnect the VPN. Check that Windows automatically reconnects to your VPN server when the network connection is restored.