We help IT Professionals succeed at work.

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

3,137 Views
Last Modified: 2012-06-22
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
Comment
Watch Question

Commented:
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.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Author

Commented:
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

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.