openvpn_client

OpenVPN Connection Script

0
(0)

Running Scripts on OpenVPN Connect and Disconnect

Running OpenVPN Client for Windows with script file allows you to create the network drives to share on servers when starting VPN connections. There are other options, such as running login scripts, printer redirects, or automated updating. This tutorial shows the installation and application of OpenVPN connection scripts.

How to do it

The OpenVPN GUI for Windows can be downloaded from the community website here. During installation, the OpenVPN directory is created under %USERPROFILE%, including the folder config, which contains the configuration files (.ovpn) that are stored from the OpenVPN GUI with File Import.

OpenVPN-in-Taskbar

Right-clicking above the OpenVPN icon icon in the taskbar opens the context menu with file import, which is saved at: %USERPROFILE%\OpenVPN\config

openvpn-config

The batch files must be in the same config directory and have the same name as the file name of the configuration (.ovpn), whereby _up must be added, as here the file name starts with VPNConfig and appended _up, VPNConfig_up.bat.

openvpn_verbindungsskrip

The contents of the connection-building batch file may look like this so that a network drive is mapped to the server after connecting to OpenVPN.

VPNConfig_up_bat
Illustration: VPNConfig_up.bat

It is mapped with VPNConfig_up.bat the network drive I: to the server tower, here in this example with domains login city.local as user user with password password. If you do not want to have a visible password in the batch, you remove it, the password prompt will called.

VPNConfig_down_bat
Illustration: VPNConfig_down.bat

After disconnecting the OpenVPN connection, the batch VPNConfig_down.bat disconnects the network drives.

explorer-openvpn-config

The batch files must be in the same directory, here in the user profile under OpenVPN along with the ovpn file in the config directory.

If you rename the configuration file before importing, here VPNConfig.ovpn i.e. CityOffice.ovpn, then this name appears in the context menu when connecting to destination in the OpenVPN GUI. The batch files must have the same names before _up and _down.

In order for the server name to be resolved at net use, the entry dhcp-option DNS has to modify in the file VPNConfig.ovpn.

In this example, the DNS 192.168.3.110 is on the remote network to which we connect to OpenVPN. If there is no DNS on the network, the IP address must be specified instead of the host name.

In the OpenVPN settings you will find the possibility to determine the location of the configuration files and log files, here the path to the files can be changed, also there is the possibility to determine the extension (.ovpn). Adjusting the paths can be useful, for example, when using roaming profiles, creating the folder for the OpenVPN connections under %APPDATA%, or when using offline folders, this can be set individually.

OpenVPN Settings
Figure: OpenVPN Settings

In the OpenVPN settings, the values for script files can be changed if necessary, in the script timeout area for preconnect script timeout, in this case the batch file VPNConfig_up.bat, and VPNConfig_down.bat for timeout for Disconnect script.

Example of a Netlogon Connection Script (xxxxxxxx_up.bat):

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *