Automatically mount network drive when openvpn connects

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
lucasd
OpenVpn Newbie
Posts: 3
Joined: Tue Mar 08, 2011 4:18 am

Automatically mount network drive when openvpn connects

Post by lucasd » Tue Mar 08, 2011 4:24 am

Hi

Is there a way or a script i can add to the config file that will automatically mount a network drive
once openvpn has connected from a clients computer to the server?

Currently i have a script which they click on once the vpn is connected but would love to automate the whole
process.

Cheers,

Lucas

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: Automatically mount network drive when openvpn connects

Post by janjust » Tue Mar 08, 2011 10:47 am

yes this is possible ; add a 'up' or 'route-up' script to the config which maps the drives in the background. If you're using the OpenVPN GUI it is also possible to create a GUI-specific post-connect script: if your openvpn configuration is named <config>.ovpn then place a script named <config>_up.bat in the same directory. This script will be executed after the openvpn tunnel turns "green".

lucasd
OpenVpn Newbie
Posts: 3
Joined: Tue Mar 08, 2011 4:18 am

Re: Automatically mount network drive when openvpn connects

Post by lucasd » Thu Mar 10, 2011 4:42 am

Thanks for the help, i was able to get it to work with the <config>_up.bat
Would you have any examples you could point me in the right direction of
the --up and --route-up scripts included in the client config file.

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: Automatically mount network drive when openvpn connects

Post by janjust » Thu Mar 10, 2011 7:03 am

a 'route-up' configuration in the client config file would look something like

Code: Select all

script-security 2
route-up route-up.bat
or

Code: Select all

script-security 2
route-up ..\\scripts\\route-up.bat
In the first example the route-up.bat file must be present in the same directory as the openvpn config file (usually c:\program files\openvpn\config) ; in the second example the script must be present in c:\program files\openvpn\scripts

For Windows Vista/7 client it is sometimes useful to use

Code: Select all

script-security 2 system
route-up ..\\scripts\\route-up.bat
as you can avoid some privilege escalation problems with that , but this is considered less secure.

lucasd
OpenVpn Newbie
Posts: 3
Joined: Tue Mar 08, 2011 4:18 am

Re: Automatically mount network drive when openvpn connects

Post by lucasd » Thu Mar 10, 2011 12:11 pm

perfect thanks again.

Post Reply