Script to disconnect mapped drives and connect mapped maps

I need a script that will prompt the user for their location, then execute based on the user input.  Either choice will disconnect X, Y, and Z mapped drives and then map X, Y and Z based on their choice.  They will have two location choices to select from.  Based on their choice, the script will map the three drives based on UNC paths I provide to the script.  Feel free to include any additional intelligence into the script based on experience.  In the past, I have used a batch file for this but it has not done too well with consistently performing.  Sometimes it would not delete or not remap.  Sometimes it will say the drives were already in use, so I am preferring VB script since it can likely better handle things.  Thanks!
murrycAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
Is your location based on IP address/subnet.  If so, you do not have to have user ask for location and automatically map and unmap the drives.  You also do not need a VB script to do it, you could use batch file.  Below are two examples:

Example 1 (disconnect/reconnect based on default gateway)
ipconfig | find "Gateway" | find "x.x.x.x" > nul
if not errorlevel 1 goto site1

Rem  User is in site 2
net use x: /del
net use y: /del
net use z: /del
net use x: \\server1\share1
net use y: \\server2\share1
net use z: \\server3\share1
exit

:site1
Rem user is in site1
net use x: /del
net use y: /del
net use z: /del
net use x: \\server1\share2
net use y: \\server2\share2
net use y: \\server3\share2

Example 2
:Choice
Rem User is given choice to select site
@Echo off
Echo *********************************
Echo *                                                                  *
Echo *                                                                  *
Echo *        A = Site 1                                         *
Echo *        B = Site 2                                         *
Echo *                                                                  *
Echo *********************************
Echo.
Echo.
set /P c=Select your location
if /I "%c% EQU "A" goto site1
if /I "%c% EQU "B" goto site2
goto :Choice

:site2
Rem  User is in site 2
net use x: /del
net use y: /del
net use z: /del
net use x: \\server1\share1
net use y: \\server2\share1
net use z: \\server3\share1
exit

:site1
Rem user is in site1
net use x: /del
net use y: /del
net use z: /del
net use x: \\server1\share2
net use y: \\server2\share2
net use y: \\server3\share2
exit

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
murrycAuthor Commented:
Ok, I like the gateway option.  Can you code more specifically how it chooses the correct site based on that IP?

Site 1 is 192.168.0.204

Site 2 is 192.168.0.252
Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
What you need to do is identify all the gateways for your LAN and then you could change the script to ensure other sites are included (you specify the gateway).

The script is written where you specify the gateway is let's say x.x.x.x and you identify it as site 1 (i.e. 10.10.1.1 is gateway for San Francisco office, etc.).

You could also add another menu item where the user has the choice of selecting None which means he/she is not at any of the specified sites and for which you could set default mapping.  Let me know what you want and I could do it for you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.