How to automatically connect VPN to specific apps on Windows 10

With Windows 10 PowerShell (cmdlets), you can easily add applications to automatically activate VPN connections when they launch.

With Windows 10 PowerShell (cmdlets), you can easily add applications to automatically activate VPN connections when they launch. Automating this task means you won't have to worry about connecting to a VPN when using certain apps.

To take advantage of this functionality in PowerShell, you will first need to add a VPN service to your computer if you don't already have one. Check out the article: How to create a VPN on Windows 10 for how to do it.

How to add automatic VPN activation feature

After establishing a VPN connection on Windows 10, you will need to open PowerShell as an administrator.

Picture 1 of How to automatically connect VPN to specific apps on Windows 10
Open PowerShell as admin

Click Yes right in the prompt that appears to allow access to the computer.

In the PowerShell window, enter the following command, then replace and with the name of the VPN connection, plus the file path to the application you want to use, respectively:

 Add-VpnConnectionTriggerApplication -Name "" –ApplicationID "" 

Note include the quotes in the command.

Hit Enter to run the command. PowerShell warns you that Split tunneling is disabled by default. To continue, you must confirm and enable this feature first.

Type Y when the prompt appears, then press Enter again to finish.

Picture 2 of How to automatically connect VPN to specific apps on Windows 10
Type Y when the prompt appears

You must enable Split tunneling to enable automatic connection to the VPN without human intervention.

Split tunneling prevents Windows from routing all network traffic through the VPN, when the application activates it to start. Instead, split tunneling divides the traffic and only data from the listed application is transferred over the VPN.

Enter the following command in PowerShell:

 Set-VpnConnection -Name "" -SplitTunneling $True 

. and replace with the name of your VPN (note the quotation marks), then press Enter .

Next, in case you accidentally close the application and do not want the connection to terminate, you can set the timeout buffer to restart the application.

Import:

 Set-VpnConnection -Name "" -IdleDisconnectSeconds 

. go to PowerShell and press Enter . Replace with your connection name and with the number of seconds to wait until the connection is terminated.

Now, when the application closes, Windows will wait 10 seconds before terminating the VPN connection. You can change this number as you like or skip this step altogether.

How to see which apps automatically activate VPN

There are several ways you can check to see which applications have been installed to automatically activate the VPN connection. You can use a command in PowerShell or edit the phonebook file in File Explorer.

If the VPN suddenly starts and you're not sure why, you can use one of the following methods to determine which application has enabled it.

Use a PowerShell cmdlet

To use this method, click the Start button and enter Powershell. Right-click on Windows PowerShell and then select Run as Administrator from the menu.

Click Yes right in the prompt that appears to allow access to the computer.

In the PowerShell window, enter the following command, but replace it with your VPN connection name, then press Enter :

 Get-VpnConnectionTrigger -ConnectionName 

Use File Explorer

Another option is to track dial-up phonebook files in File Explorer. You can open it in a text editor and see the list of VPN enabled apps.

The phonebook file provides a standard way for Windows to collect and specify the information needed for setting up Remote Access Connection (RAS). This file contains information such as IP address, port, modem settings and information you are looking for about applications that can trigger connections.

To get started, open File Explorer and paste the following folder in the address bar, but replace it with the current username, then press Enter :

 C:UsersAppDataRoamingMicrosoftNetworkConnectionsPbk 

Right-click on 'rasphone.pbk' and then select the text editor in which you want to open the file.

Picture 3 of How to automatically connect VPN to specific apps on Windows 10
Right click on 'rasphone.pbk'

This file contains all the VPN connections on your computer, so if you have multiple VPNs, you may have to sift through a lot to find the applications you want. Each application is stored in the 'ClassicApplicationIDs' function as the direct file path.

Fortunately, if you don't want to scroll through each application, most text editors have a Find feature. Press Ctrl + F , type 'ClassicApplicationIds' into the text field, then press Enter .

Picture 4 of How to automatically connect VPN to specific apps on Windows 10
Enter 'ClassicApplicationIds' in the text field

How to remove the automatic VPN activation feature

If you accidentally add a wrong application or no longer want a VPN to activate when launching specific applications, you can delete them using a similar cmdlet in PowerShell.

To remove the automatic VPN activation feature, open Powershell with admin rights.

Click Yes in the prompt that appears to allow access to the computer.

In the PowerShell window, enter the following, but replace and with the name of the VPN connection plus the path to the corresponding application:

 Remove-VpnConnectionTriggerApplication -Name "" –ApplicationID "" 

PowerShell prompts you to confirm deletion of the application from the automatic activation list. Type Y and press Enter .

Repeat this step for every application you want to remove from the list.

Update 14 February 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile