OVPN Win32 Map Network Drive on Logon?



  • I have set up OpenVPN for my roaming users, many of whom are using laptops to connect to the VPN.  Is there any way I can have Windows automatically mount a network drive (\192.168.x.x\share) as soon as the openVPN client is connected?  Obviously I don't want Windows to try to connect when the users aren't on the VPN, but as soon as they initiate the VPN connection they will need the network drive.

    Any assistance is greatly appreciated!



  • On the OpenVPN Gui page, it lists the following as one of the features:

    "Execute a batch file before/after connecting and before disconnecting."

    I assume I could just add in one of the following commands into a batch file and it would work?

    net use o: \server\share

    So I guess the question is now what do I add in to the ovpn.conf file to tell it to run a batch file?



  • I've searched around, and apparently all I need to do is put my script in the config directory with the name of 'xxxx_up.bat' (where xxxx is the connection name).

    This looks like it will work, but I can't easily test it until I get home from work.



  • And if you need to hide popup script window, you can set a registry key "show_script_window" in HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI to "0"
    :D



  • Ok, so I've created the .bat file with the following (sanitized) contents:

    net use z: \\host\sharename mypassword /user:DOMAIN\myusername /persistent:yes
    

    If I run the script manually after connecting to the VPN, it works like a charm.  However it always times out when it is automatically run by OpenVPN.  Is there anything I can do to delay the script by a few seconds?



  • Download the DOS sleep command:

    http://www.computerhope.com/dutil.htm

    Then use it before the net use command…

    sleep 15
    net use ...



  • wouldnt the "-route-up cmd" in conjunction with "-route-delay" command from openVPN itself work too?
    (i didnt try it but it might be worth a shot)

    –route-delay [n] [w]
        Delay n seconds (default=0) after connection establishment, before adding routes. If n is 0, routes will be added immediately upon connection establishment. If –route-delay is omitted, routes will be added immediately after TUN/TAP device open and --up script execution, before any --user or --group privilege downgrade (or --chroot execution.)

    This option is designed to be useful in scenarios where DHCP is used to set tap adapter addresses. The delay will give the DHCP handshake time to complete before routes are added.

    On Windows, --route-delay tries to be more intelligent by waiting w seconds (w=30 by default) for the TAP-Win32 adapter to come up before adding routes.

    --route-up cmd
        Execute shell command cmd after routes are added, subject to --route-delay.

    See the "Environmental Variables" section below for additional parameters passed as environmental variables.

    Note that cmd can be a shell command with multiple arguments.



  • I still must be missing something.  If I run my 'net mount' script manually, it works perfectly, but even with delaying the execution of the script in my ovpn config, I end up with this error:

    "C:\Program Files\OpenVPN\config>net use …(etc)
    System error 67 has occurred.

    The network name cannot be found.

    Wed Jan 09 19:54:39 2008 us=976924 Route script failed: system() returned error
    code 2
    Wed Jan 09 19:54:39 2008 us=977080 Initialization Sequence Completed
    Wed Jan 09 19:54:40 2008 us=12335 Replay-window backtrack occurred [1]"



  • are you using the windows name or the actual IP?



  • It doesn't seem to make a difference which I use.  Also, I have a a WINS machine on the VPN side of the LAN which resolves windows host names to their IPs.





  • Like I said though, the script works perfectly if I run it manually, the only time it doesn't work is when it is invoked as part of the oVPN process itself.


Log in to reply