How to Automatically Connect to a VPN for Certain Apps in Windows 10
👨‍💻
With the PowerShell cmdlet for Windows 10, you can easily add apps to automatically launch the VPN connection when it is started. Automating this task means that you don’t even have to think about connecting to a VPN when using certain apps.
To take advantage of this functionality in PowerShell, you will first have to add a VPN service to your computer if you don’t already have one.
Related: How to connect to a VPN in Windows
How to add VPN Auto-Triggering
After setting up a VPN connection on Windows 10, you will need to open an elevated instance of PowerShell. To do this, click on the “Start” button, then type “Powershell”. Right-click on “Windows PowerShell”, then select “Run as administrator” from the menu.
Click Yes at the prompt that appears to allow access to your computer.
In the PowerShell window, type the following and replace
Add-VpnConnectionTriggerApplication -Name “
Make sure to include quotes in the command.
Press Enter to run the command. PowerShell warns you that split tunneling is disabled by default. To continue, you must confirm and enable the feature before it will turn on automatically.
Type “Y” when the prompt appears, then press Enter again to quit.
You have to enable automatic split-tunneling of the trigger to connect to the VPN without human intervention.
Split tunneling prevents Windows from routing all network traffic through the VPN when the application launches it to start. Instead, it splits the traffic, and the data from the listed app will only flow through the VPN.
Type Set-VpnConnection -Name “
Then, in case you accidentally close the app and you don’t want to end the connection, you can set a timeout buffer to restart the app.
Type Set-VpnConnection -Name “
Now, when you close the app, Windows 10 will wait seconds before it terminates the VPN connection. You can make this number as you like or omit this step completely.
How to find out which apps are automatically running a VPN
There are several ways you can check to see which apps you have set to start the VPN connection. You can either use a cmdlet inside PowerShell or edit the phonebook file in File Explorer.
Related: How is PowerShell different from Windows Command Prompt
If the VPN suddenly started and you are not sure why, you can use either of the following two methods to determine which application triggered it.
Using PowerShell Cmdlet
To use this method, click on the “Start” button and type “Powershell”. Right-click on “Windows PowerShell”, then select “Run as administrator” from the menu.
Click Yes at the prompt that appears to allow access to your computer.
In the PowerShell window, type the following command, but replace
Get-VpnConnectionTrigger -ConnectionName
In our example, the command retrieves the properties of the VPN connection “VPN Canada” and displays them below.
Using File Explorer
The other option is to track a dial-up phonebook file in File Explorer. You can open it in a text editor and see the list of apps running the VPN.
A phonebook file provides a standard way for Windows to collect and specify the information it needs to establish a remote access (RAS) connection. The file contains information such as IP addresses, ports, modem settings, and – the information we’re looking for – which applications are running the connection.
To get started, open File Explorer and paste the following directory into the address bar, but replace
C: Users
Right-click on “rasphone.pbk”, then select the text editor in which you want to open the file.
This one file contains all the VPN connections on your computer, so if you have more than one VPN, you may have to sift through a lot to find the apps you want. Each application is stored within the “ClassicApplicationIDs” function as a direct path to the file.
Fortunately, if you don’t want to scroll to find every app, most text editors have a Search feature. Press Ctrl + F , type ClassicApplicationIds into the text field, then press Enter.
How to remove VPN Auto-Triggering
If you accidentally add the wrong app or you no longer want the VPN to run when certain apps are running, you can remove it using a similar cmdlet in PowerShell.
Related: Geek School: Learn to use cmdlets in PowerShell
To remove VPN autorun, click the Start button, then type “Powershell.” Right-click on “Windows PowerShell”, then select “Run as administrator” from the menu.
Click Yes at the prompt that appears to allow access to your computer.
In the PowerShell window, type the following, but replace
Remove-VpnConnectionTriggerApplication-Name”
PowerShell prompts you to confirm that you want to remove the app from the autorun list. Type “Y” and press Enter.
Repeat this step for each app you want to remove from the list.
Now, when you run the applications you selected, Windows will start the VPN connection and send traffic through it – no third-party software is required.
[ad_1]
Don’t forget to share this post with friends !