• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 753
  • Last Modified:

VB drive mapping script

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
sullivanr6
Asked:
sullivanr6
  • 3
  • 3
1 Solution
 
RobSampsonCommented:
>> 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
 
sullivanr6Author Commented:
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
 
RobSampsonCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sullivanr6Author Commented:
success. thank you.

regards,

Jason
0
 
sullivanr6Author Commented:
thanks for your help.
0
 
RobSampsonCommented:
No problem .  Thanks for the grade.

Regards,

Rob.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now