Link to home
Start Free TrialLog in
Avatar of donmanrobb
donmanrobbFlag for Canada

asked on

VBscript that will verify VPN is connected and will map network drives, remove drives when disconnected.

Hello All,

I have setup a remote access VPN for an office so that remote users can connect to access resources through Cisco VPN client. The problem is that users would like various network drives mapped when connected to the VPN.

My first thought was to have a .vbs script on the user's desktop they could double click after connecting but I'd like to automate it possible.

I would like a VB or even a batch script that runs on startup that will detect the VPN is connected and map the drives or run another script that will do so. I'm thinking that it could work a bit like this:

Ping remote server's private IP address every few minutes, if it receives a reply it would check to see if the drives are mapped already, if not it would either map the drives or run a second script that I can make later.

If it doesn't receive a reply it can check to see if the drives are mapped already, if they are it can delete the map drives and continue in a loop. All systems in the network are Windows.

Can this be done?

Cheers,
donmanrobb


If the
Avatar of doser
doser
Flag of United States of America image

I think it can be done for the most part.  You're looking at a VBScript to get the Cisco part to work and a batch file to test the mapped drives.  I"m not too sure how to get it to test every few minutes though.  You're going to need a programming guide to the VPN client so you know what the objects are you need to define.
SOLUTION
Avatar of doser
doser
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of donmanrobb

ASKER

Basically the Cisco VPN is not really a part of the script the user can manually run the program.

I'm more interested in a script that will ping a given address every few minutes and if successful will run the map statements. In batch the pings could be handled with something like: Pardon the speghetti code

@echo off
Loop
ping 192.168.1.1 -n 1 | find /i "bytes" && goto :somewhere
do something else

:something
map drives

End loop
Okay here is what I came up with for  a batch script, can someone verify my logic?


@echo off
 
:loop
 
ping 127.0.0.1 -n 2 -w 300000      ## Delay 5 Min
 
 
ping 192.168.1.1 -n 1 | find /i "bytes" && call :mapdrives   ##Ping remote resource and if successful goto mapdrive section
call :novpn         ## Ping not success go to novpn section
 
:mapdrives
net use | find /i "remoteshare" && goto :loop   ## Check if share if active restart if it is
net use //192.168.1.1/remoteshare && goto :loop ## Add share
 
 
:novpn
net use | find /i "remoteshare" || goto :loop ## If share if not added restart
net use //192.168.1.1/remoteshare /delete && goto :loop ## Remove share and restart

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial