I've been using the OpenVPN GUI with an .ovpn file (I use the one provided by free VPN SigaVPN) for about a year, and although I'm generally pleased with both OpenVPN and SigaVPN, it's getting tiring to connect manually. I'm trying to automate this process in the usual way with AutoHotKey, using my numpad's 5/Clear key:

NumpadClear::
Run C:\Program Files\OpenVPN\bin\openvpn-gui.exe --connect 1529624602320169353.ovpn
Return

But running this only serves to opens the OpenVPN GUI client itself, and forces me to continue connecting to the VPN manually.

Alternatively, providing the .ovpn file's full path:

NumpadClear::
Run C:\Program Files\OpenVPN\bin\openvpn-gui.exe --connect "C:\Program Files\OpenVPN\config\1529624602320169353.ovpn"
Return

...fails with some variation of the following error:

enter image description here

What's causing this, and exactly how can I automatically connect to my VPN with AutoHotKey?

This issue has two causes: AutoHotKey not being in the right directory to run the .ovpn file, and the OpenVPN GUI client having no support for providing the full path to the .ovpn file as part of the --connect option.

As the result, the solution is to navigate AHK to the directory which contains the .ovpn file and to run the script directly from that directory. This can be accomplished by using AHK's SetWorkingDir function:

NumpadClear::
SetWorkingDir, C:\Program Files\OpenVPN\config 
Run C:\Program Files\OpenVPN\bin\openvpn-gui.exe --connect 1529624602320169353.ovpn
Return

Note the peculiar AHK syntax of separating the function from the parameter with a comma, and remember to change the path here to reflect the one which contains your own .opvn file.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.