How to connect to OpenVPN GUI with AutoHotKey

0

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?

Hashim

Posted 2018-12-02T19:29:16.777

Reputation: 6 967

Answers

1

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.

Hashim

Posted 2018-12-02T19:29:16.777

Reputation: 6 967