I have been trying to come up with a way to interact with openvpn on windows. I did fine the openvpn.exe but there are no commands that will use a config file to connect with a vpn server. I am using nordvpn by the way. Specifically a tcp Canadian server. I did find some people suggesting to use the openvpn-gui.exe to run the program but it defeats the purpose. I want t to completely be on command line. Secondly, i need the command line to work as i want to integrate openvopn into a script which will download stuff from the internet. Anyone with any idea how to do it?
04 Answers
For anyone looking into this in 2021, please find below a connect and a disconnect.
To connect
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command connect yourconfigfile.ovpn To disconnect
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command disconnect yourconfigfile.ovpn For windows users... Both of these can be placed in a .bat file and automated with task scheduler, works like a charm.
Another CMD example:
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --connect config.ovpn Replace 'config.ovpn' by your configuration file. You also may have another path to openvpn-gui.exe.
It will work if you have no openVPN correctly installed so you can't run openvpn-gui ... from cmd.
So I figured out the answer to the problem. To control openvpn from command-line on windows:
- Set the Environment Variable so you can access the openvpn-gui.exe from command-line.
- Type this command:
openvpn-gui --connect [config file]. (You are going to need the config file so download it from your vpn provider)
If you don't want to type the password every time you run the script, edit the config file to read the username and password from a .txt file. Here's a link that can help you do that:
You can actually use the config file with openvpn.exe, but you must provide the full path to it unlike with openvpn-gui.exe:
openvpn.exe --config "path/to/config.ovpn"