Connect to VPN on Startup Before Login

If like me you have a need to establish a VPN from a host to another or even to a secure management network, you might like to configure your host device to establish a connection at boot rather than lose remote connectivity if the device reboots. In my case I chose to use OpenVPN Cloud as it was a simple 2 node requirement, I was able to get the host specific configuration by following the guide from https://openvpn.net, check it out here https://openvpn.net/cloud-docs/switching-to-manual-profile-distribution-creating-a-device/

To achieve this using OpenVPN, simply download and install the OpenVPN client most suited to your environment https://openvpn.net/index.php/open-source/downloads.html

Install the client, this guide assumes the defaults. Once complete, place your configuration file in the folder C:\Program Files\OpenVPN\config\ and open Task Scheduler. Click Action followed by Create Task, name the task and provide a description as appropriate. Select the Run whether user is logged on or not and set Run with highest priveleges, change the Operating system for which the task is meant.

Click the Triggers tab, New and change the task to begin At startup. I set the task to delay for 1 minute but that is entirely up to you, once you’re happy click OK. Click the Actions tab, with the Action set to be Start a program and enter the following under Program/script;

"C:\Program Files\OpenVPN\bin\openvpn-gui.exe"

Add the arguments to ensure the correct profile is selected

--connect YourVPNFileNameHere.ovpn

Next click on the Conditions tab and deselect everything, unless you want one of the settings enable. We then open the Settings tab but leave all of the defaults, only adding a tick for Run task as soon as possible after a scheduled start is missed, just in case the host gets caught up with other processes. Then we just press OK.

Then all that is left is to test it.