Autostart OpenVPN based on WiFi Network

How to customize and extend your OpenVPN installation.
Post Reply
OpenVPN User
Posts: 10
Joined: Thu Apr 20, 2017 6:44 pm

Autostart OpenVPN based on WiFi Network

Post by IceBoy » Thu Apr 20, 2017 7:10 pm

Currently running OpenVPN GUI v10 on a Windows 10 laptop.

I am using OpenVPN to connect to my home network whenever I'm out of the house. I'd like for OpenVPN to automatically startup and connect to my preferred server (home network) whenever I'm not at home; more specifically, I'd like to be able to specify which WiFi networks should trigger OpenVPN to run and connect. I found a few threads about autostart, but I think I'll need some kind of script to be able to specify when to auto-connect based on which WiFi network is connected. If I've overlooked something obvious, I apologize in advance -- I used to consider myself technically savvy until I read some of these threads.

OpenVpn Newbie
Posts: 2
Joined: Wed May 17, 2017 4:51 pm

Re: Autostart OpenVPN based on WiFi Network

Post by TCS_Taylor » Wed May 17, 2017 5:23 pm

I would suggest writing a VBscript which starts at login.
have it do the following (pseudo code)

Code: Select all

vpnconnected = false
loopvar = neverstop
do until loopvar = stop
pull the SSID of the connected WIFI network
if SSID is in a predefined list of networks to vpn from and vpnconnected = false
   kill all openvpn.exe and openvpn-gui.exe
   run openvpn-gui.exe --connect %openvpnfile% (where %openvpnfile% is the ovpn file you want to use to connect)
   vpnconnected = true
end if
I'm doing something like this with our login script. the login script checks to see if the user is local, if they aren't it automatically kicks off the openvpn-gui.exe, passing it the end user's OVPN.

hope this helps!


Post Reply