Automounting Samba Shares over OpenVPN

So you've got a working OpenVPN setup, but now you want to be able to access the Samba shares hosted on the remote network.

It's very easy to do manually, but most users don't want to have to learn to map network drives (or shudder use some of that commandline black magic). Thankfully, they don't need to as you can tell OpenVPN to do the legwork for them;

 

 

A minor downside is that this can't be configured on the server (which makes sense as the commands needed would differ between each OS), and so needs to be configured for each client.

Edit the clients OpenVPN Configuration file (if you followed my tutorial it's probably named client.ovpn) and add the following to the bottom;


route-up client_up.bat

Now open Notepad and enter the following


net use [Driveletter] \\[Server]\[Share]

Where Driveletter is the letter you want to use, Server the servername and Share the sharename;

 

net use J: \\Myserver\Someshare

Save this as client_up.bat in the same folder as client.ovpn. Now when you connect to OpenVPN this script will run and map the samba share to the drive letter you specified.

 

Notes

In my tutorial, I explained how to configure OpenVPN to run as an Administrator. If you are running Windows 7 (and possibly Vista), this creates something of a headache. The command will complete successfully, but the drive won't be available to the ordinary user.

Sadly, I've not yet found a fix for this!