This gist contains a Windows task that will automatically connect to the home.ovpn network when connecting to any Wi-Fi network other than "Peace", and another task that will disconnect from the OpenVPN whenever you disconnect from Wifi.
- Download the xml files from this gist.
- Modify the Exec Arguments at the bottom of the Connection file to work with your network configuration by:
- Replacing "Peace" with your home Wi-Fi network name
- Replacing "home.ovpn" with the name of the ovpn network config file you wish to use.
- Open "Task Scheduler"
- Use the "Import task..." action and choose the files you downloaded.
Windows will display the command dialog while the commands are executing. This can be avoided with some additional system configuration.
- Open Task Scheduler
- Open Properties for both tasks
- Click "Change Users or Groups"
- Type in System
- Click "Check Names"
- Click OK
- If you have a username and password for your account:
- Open your ovpn profile. It can be found in your user directory under OpenVPN\config\profilename\
- Find the line: auth-user-pass
- Add "credentials.txt" to the end of that line
- Save your changes
- Create a file in the same directory called "credentials.txt"
- Add your username to the first line of the file, and your password to the second line of the file
I know this seems unsafe, but only system process and system admins will be able to access this file after you move it at the next step.
- Copy/Move the OpenVPN folder in your UserProfile, to C:\WINDOWS\system32\config\systemprofile
- Run the connect task
- Check the log file in C:\WINDOWS\system32\config\systemprofile\OpenVPN\logs to see if it connected successfully