[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VB drive mapping script

Posted on 2008-10-13
6
Medium Priority
?
751 Views
Last Modified: 2012-05-05
Hello All,
Thank you for assisting. I am looking for a visual basic script to map network drives. I would like the script to map drives regardless if there are currently mapped or not.

I've seen quite a few sets of generic scripts that call arrays and prompt user dialog messages... I would like a simple script to map drives (10 or more), and passively pass over existing drives should they already have a mapping.

My objective is to have this script run in place of my current .bat file, vb is needed for my AD integration. Is it possible for the script to not disconnect mapped drives, only to remap them???

Many thanks for your help,

J
0
Comment
Question by:sullivanr6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 22707123
>> Is it possible for the script to not disconnect mapped drives, only to remap them???
No.  For a drive letter to be re-mapped to another location, it must first be disconnected.

This script will do that for you.

Regards,

Rob.
Set objDict = CreateObject("Scripting.Dictionary")
objDict.Add "G:", "\\server\share\gshare"
objDict.Add "H:", "\\server\share\hshare"
objDict.Add "I:", "\\server\share\ishare"
objDict.Add "J:", "\\server\share\jshare"
objDict.Add "K:", "\\server\share\kshare"
objDict.Add "L:", "\\server\share\lshare"
objDict.Add "M:", "\\server\share\mshare"
 
Set objNetwork = CreateObject("WScript.Network")
' Disconnect all drives first
For Each strDrive In objDict
	objNetwork.RemoveNetworkDrive strDrive, True, True
Next
' Map the drives
For Each strDrive In objDict
	objNetwork.MapNetworkDrive strDrive, objDict(strDrive), False
Next

Open in new window

0
 
LVL 3

Author Comment

by:sullivanr6
ID: 22707263
thank you for your prompt reply Rob,

The script you wrote has failed on line "objNetwork.RemoveNetworkDrive strDrive, True, True"
...as i understand the error message it failed because the drives that I am trying to map are not currently in use.

This script needs to map new and "remap" existing drives.

Thank you for your help,

Jason
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 22707392
Oh whoop!  Yeah, forgot to check if the drive already exists.....

This will map all drives, whether they were mapped or not....

Regards,

Rob.
Set objDict = CreateObject("Scripting.Dictionary")
objDict.Add "G:", "\\server\share\gshare"
objDict.Add "H:", "\\server\share\hshare"
objDict.Add "I:", "\\server\share\ishare"
objDict.Add "J:", "\\server\share\jshare"
objDict.Add "K:", "\\server\share\kshare"
objDict.Add "L:", "\\server\share\lshare"
objDict.Add "M:", "\\server\share\mshare"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
' Disconnect all drives first
For Each strDrive In objDict
	If objFSO.DriveExists(strDrive) = True Then objNetwork.RemoveNetworkDrive strDrive, True, True
Next
' Map the drives
For Each strDrive In objDict
	objNetwork.MapNetworkDrive strDrive, objDict(strDrive), False
Next

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:sullivanr6
ID: 22707513
success. thank you.

regards,

Jason
0
 
LVL 3

Author Closing Comment

by:sullivanr6
ID: 31505699
thanks for your help.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22707529
No problem .  Thanks for the grade.

Regards,

Rob.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question