Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / Windows 10 / Windows: Auto Reconnect to VPN on Disconnect

November 3, 2023

Windows: Auto Reconnect to VPN on Disconnect

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.

VPN connection profiles, which are available to all Windows users, are stored in the %ProgramData%\Microsoft\Network\Connections\Pbk\rasphone.pbk 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)

rasphone.pbk redial options

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

EventIDSourceEvent description
20226RasClient (Application log)The user username dialed a connection named VPNConnectionName which has terminated. The reason code returned on termination is 829.
10000NetworkProfile (Microsoft-Windows-NetworkProfile/Operational log)Network Connected

event id 20026 - vpn connection dropped

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):

  1. Log: Application , Source: RasClient , EventID: 20226
  2. Log: Microsoft-Windows-NetworkProfile/Operational , Source: NetworkProfile , EventID: 10000

Create reconnection triggers in Task Scheduler

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
  • Program/script: %windir%\System32\rasdial.exe
  • Argument: YourVPNCOnnectionName

task scheduler - reconnect to vpn automatically

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

You can list VPN connections on Windows using PowerShell:

Get-VpnConnection|select name,ServerAddress,TunnelType

powershell - list vpn profiles on windows

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.

Previously, we showed you how to configure a similar task to automatically disconnect from Wi-Fi when your computer is connected to an Ethernet network.
1 comment
2
Facebook Twitter Google + Pinterest
PowerShellWindows 10Windows 11Windows Server 2019
previous post
SCCM and WMI Query to Find All Laptops and Desktops
next post
How to Install and Configure TFTP Server and Client on Windows

Related Reading

Unable to Connect Windows 10 Shared Printer to...

March 11, 2024

How to Get My Public IP Address with...

October 24, 2023

How to Unblock a File Downloaded from Internet...

November 17, 2023

How to increase KMS current count (count is...

March 12, 2024

Auto-mount VHD/VHDX File at Startup in Windows

February 20, 2024

Error 0x0000007e: Windows cannot connect to network printer,...

March 11, 2024

How to Clear Event Viewer Logs on Windows

November 9, 2023

Booting Windows from GPT Disk on BIOS (non-UEFI)...

March 11, 2024

1 comment

George January 25, 2018 - 8:14 pm

Thanks SO much for this guide. After upgrading from W7 to W10, this was bugging the hell out of me. Thank to this, I was even able to create a “VPN Alternate” task, which looks for an 809 Error Code (ERROR_VPN_TIMEOUT aka VPN server unresponsive) in the Event Log and then dial an alternate VPN server. I simply created the same Tricky Task as above, but edited this line of the XML query:
*[EventData[Data[4]=’829′ or ‘629’]]

…to this:
*[EventData[Data[4]=’809′]]

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Encrypt Any Client-Server App Traffic on Windows with Stunnel

    June 12, 2025
  • Failed to Open the Group Policy Object on a Computer

    June 2, 2025
  • Remote Desktop Printing with RD Easy Print Redirection

    June 2, 2025
  • Disable the Lock Screen Widgets in Windows 11

    May 26, 2025
  • Configuring Windows Protected Print Mode (WPP)

    May 19, 2025
  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Connect and Query MySQL or MariaDB with PowerShell
  • How to Unblock a File Downloaded from Internet on Windows
  • PowerShell Remoting via WinRM for Non-Admin Users
  • How to Clear Event Viewer Logs on Windows
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top