OpenVPN Map Drives At Login

Every so often I have clients requesting that OpenVPN GUI automatically map networked drives once connected to their OpenVPN Server.  Fortunately OpenVPN GUI has built in support for running batch scripts once Connected or Disconnected. Note this tutorial is for the Windows based OpenVPN GUI client only. So without further ado, here we go. The process is rather simple, all that is needed are two batch files named the same as the .ovpn file with either _Up or _Down appended to the end. Below you will see the files highlighted in yellow. openvpn-gui-batch

It is important to note that these files must be in the same directory as your .ovpn configuration file. The contents of the files can be seen below. It seems fairly obvious, but note the Home_Up.bat file will run after connected and the Home_Down.bat will run after disconnected.

Home_Up.bat

Home_Down.bat

Did you find this article useful? Why not share it with your friends?

4 thoughts on “OpenVPN Map Drives At Login

  1. Hi, could you please share your .ovpn file?

    I’ve been trying to make it work but the bat file (Home_up.bat) only works AFTER the connection is made (Initialization Sequence Completed), otherwise I receive a “Network not found” error. Are you using –up option?

    Thank you

    1. Jorge,

      Unfortunately that is how it works. The .bat file gets called after connected. Just ensure that the .bat file is properly named. It needs to be named the same as your config with the _up.bat at the end. SO for example if I had a “office.ovpn” config file, the batch file would need to be named “office_up.bat”. Hope that helps.

  2. Might as well have ‘Home_Down.bat’ cleanup everything. Leaving those labels behind is a bit sloppy.


    @echo off

    REM Remove Mapped drives
    net use W: /delete
    net use X: /delete

    REM Cleanup added registry entries
    reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##172.16.12.10#Admin /f
    reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##172.16.12.10#Downloads /f

    EXIT

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.