How can one use the command-line to use openvpn on windows?
Asked Answered
C

6

14

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?

Colostrum answered 27/4, 2020 at 10:38 Comment(0)
G
23

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.

Guinna answered 23/8, 2021 at 21:44 Comment(0)
P
7

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.

Plain answered 25/12, 2020 at 13:9 Comment(0)
P
4

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"
Pedalfer answered 25/3, 2022 at 15:31 Comment(0)
C
2

So I figured out the answer to the problem. To control openvpn from command-line on windows:

  1. Set the Environment Variable so you can access the openvpn-gui.exe from command-line.
  2. 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: https://help.vpntunnel.com/support/solutions/articles/5000613671-how-do-i-save-my-username-password-in-openvpn-for-automatic-login-

Colostrum answered 5/5, 2020 at 0:34 Comment(0)
C
1

Instructions

Step 1. Go to the correct location for x64 systems:

cd "%ProgramFiles%\OpenVPN Connect" Note: if you have the 32 bits program installed on a 64 bits OS, replace %ProgramFiles% with %ProgramFiles(x86)%.

Step 2. Install the system service:

ovpnconnector.exe install

Step 3. Specify connection profile to use (optional):

ovpnconnector.exe set-config profile <FULL_PATH_AND_FILENAME_TO_PROFILE.OVPN> Note: if your OpenVPN Connect installation file was downloaded from Access Server or OpenVPN Cloud and came with a bundled autologin connection profile, then you can skip step 3. It will then simply default to the bundled connection profile. It can be found in the program location with the name "ovpnconnector.ovpn" - that is the bundled connection profile.

Step 4. Specify the path to a log file (optional):

ovpnconnector.exe set-config log <FULL_PATH_AND_FILENAME_TO_LOGFILE.LOG> Note: if you skip step 4, the service will write to the default log file in the program location with the name “ovpnconnector.log”.

Step 5. Start the service:

ovpnconnector.exe start The service will now start the VPN connection and log output to the log file.

Note: you will not receive feedback after starting the service if the connection succeeded or not. You can check the log file or use the ping command to verify that the connection is now up and running.

Important: OpenVPN Connect client should not be running, otherwise service startup will abort.

Clementineclementis answered 6/7, 2022 at 8:28 Comment(0)
E
0

You may use two different solutions to run OpenVPN client from the command line. See argument to provide a custom config folder if you don't want to copy files to C:\Program Files\OpenVPN\config\

Use standalone without a windows service
Run as an administartor or user-level process. OpenVPN status is printed to a current dos prompt console. This does not need a service process to run.
"c:\program files\openvpn\bin\openvpn.exe" --cd "c:/data/vpnconfig/" --config servicex.ovpn

Use gui+windows service
Make sure openvpn service process is run. OpenVPN status is printed to a trayicon gui app window.
sc start "OpenVPNServiceInteractive" | sc query "OpenVPNServiceInteractive" | sc stop "OpenVPNServiceInteractive"

"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --silent_connection 0 --show_script_window 1 --show_balloon 2 --config_dir "c:/data/vpnconfig/" --command connect "servicex.ovpn"

My experience is both work fine but openvpn-gui.exe(+service) is better at handling an auto reconnection. About the multiple openvpn exe binaries.

OpenVPNServiceInteractive, autostart=yes
- allows openvpn-gui.exe non-privileged access(from user level app) to a privileged openvpn.
 C:\Program Files\OpenVPN\bin\openvpnserv.exe
OpenVPNService, autostart=no
- starts all config files at boot.
 C:\Program Files\OpenVPN\bin\openvpnserv2.exe
openvpn-gui.exe
- trayicon app, connects to a windows service.
openvpn.exe
- openvpn connection app
- started as a standalone app or gui+windows service.

Gui app arguments: https://community.openvpn.net/openvpn/wiki/OpenVPN-GUI-New

Entitle answered 17/8, 2023 at 8:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.