Category Archives: Howto Tutorials (EN)

Knowledge Network for Tutorials, Howto’s, Workaround, DevOps Code for Professionals.

OpenVPN Connection Script

Running Scripts on OpenVPN Connect and Disconnect

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

How to do it

The OpenVPN GUI for Windows can be downloaded from the community website here. The OpenVPN client can also be deployed using winget ran in the command prompt.

C:\> winget install --id OpenVPNTechnologies.OpenVPN

Upon 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 Tasklbar click Import file

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 Connection Script

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

Edit OpenVPN_up.bat in Notepad
Edit OpenVPN Connection Script VPNConfig_up.bat in Notepad

It is mapped with VPNConfig_up.bat the network drive I: to the server tower, here in this example being login against domain city.local as username max using password pass123. If you do not want to have a visible password in the batch, you can remove it so the password prompt will by called.

Edit OpenVPN_down.bat in Notepad
Edit OpenVPN Connection Script VPNConfig_down.bat in Notepad

After disconnecting the OpenVPN connection, the batch VPNConfig_down.bat does 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 it, here the 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:
dhcp-option DNS 192.168.3.110

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.

OpenVPN Settings

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 Advanced

In the OpenVPN Settings Advanced, 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):
@echo off
timeout 5
REM mapping network printer
rundll32 printui.dll,PrintUIEntry /in /n \\tower\laserjet_office
REM mapping network drive
net use I: \\tower\office /persistent:no /user:city\max pass123
REM wait along two pings
ping localhost -n 2 > null
REM pop-up greeting message
echo msgbox("Welcome %USERNAME% on %USERDOMAIN%."),vbInformation , "Message"> %temp%\msg.vbs 
%temp%\msg.vbs
REM delete message
erase %temp%\msg.vbs

How to use Windows 10 clipboard history

Starting with the feature update October 2020, Windows 10 will come with new clipboard history features as announced.

windows clipboard history

The clipboard history which is long awaited by Windows users, now this allows to store multiple text elements, images or even files on the clipboard.

The new clipboard can now save up to 25 entries and displays text and images in a history. Save multible items to the clipboard for use later. Press the Win+V key to view your clipboard history and paste from it.

The latest items are always placed at the beginning, which same as previously copied with Ctrl+C. Clicking on an item to paste it from the cursor position, for example in Notepad or in a Word document. By clicking the pin button on the right of an entry, a pop up window appears with the option to delete an entry or delete all, more on this in the next paragraph. Win+V still paste the last item from clipboard.

By clicking the pin button on the right of an entry, a pop up window appears with the options. The new practical feature can be found on the Pin (P).

The new practical feature can be found on the Pin (P), which is available by clicking on the pin button to the right of the entry. This means that the entries remain on the clipboard, even during a Windows restart or if the clipboard history is completely removed with a click to Delete All.

The clipboard history can be turn it on in the settings – by entering clipboard in the search box.

The clipboard history can be turn it on in the settings - by entering clipboard in the search box.
The clipboard history can be turn it on in the settings - by entering clipboard in the search box.
Figure: Enable Windows Clipboard History

Clipboard in Windows 11

Copy images and text from one PC to another with a cloud-based clipboard. Not only can you can paste from your clipboard history, but you can also pin the items you find yourself using all the time.

To get to your clipboard history, press Windows logo key + V. From the clipboard history, you can paste and pin frequently used items by choosing an individual item from your clipboard menu. Pinning an item keeps it from being removed from the clipboard history to make room for new items.

Clipboard items share to another Windows device

Select Start > Settings > System > Clipboard.

Select Sync across devices and toggle it on.

Select Automatically sync text that I copy. The sync feature is tied to your Microsoft account, or your work account, so remember to use the same login information on all your devices.