Introduction to Map Network Drive - Multiple Drives
If a job is worth doing, then it's worth doing well. Once you have mastered the basic MapNetworkDrive method, you may wish
to add more drive letter mapping to your Windows logon script. Here is how you map multiple drives to network shares. Topics for MapNetworkDrive Multiple Drives
Perhaps in addition to a home folder, your users need to access a second shared folder on the server. The answer is one logon script which maps both shares. An alternative scenario is that you are building a
script which maps drives depending on which group a user is a 'member of'. In this instance. you create a selection of mapped drives, but only one is actually implemented.
Our objective is to map two drives, M: and P: with a logon script. The corresponding shares are held on a Windows 2003 server. However, you could use any Microsoft machine later than Windows
95 to host the shared folders. Pre-requisites for MapNetworkDrive - On Line 15 change the server name from '\\alan' to your server name.
- Make sure that your server has a share called '\drivers', and another called 'download reports'. Alternatively, edit the sharename in the script, and type in the name of your UNC path.
Instructions for multiple Mapped Network Drives - Copy and paste the script below into notepad.
- Change the server name from "\\alan to the name of your server.
- Make sure that you have not one, but two network shares on your server.
- Save the file with .vbs extension e.g. MNDMultiple Drives.vbs.
- Double click the logon script and check in your Windows Explorer for two new drives called : drivers on 'alan' (M:) and
download reports on 'alan' (P:).
' TwoMap.vbs - Map Network Drive to M: and P: ' Example of VBScript Mapping two drives in one script. ' Author Guy Thomas http://computerperformance.co.uk/ ' Version 1.6 - April 24th 2005 '
-----------------------------------------------------------------' Option Explicit Dim objNetwork, strRemotePath1, strRemotePath2 Dim strDriveLetter1, strDriveLetter2
strDriveLetter1 = "M:"
strDriveLetter2 = "P:" strRemotePath1 = "\\alan\drivers" strRemotePath2 = "\\alan\downloads reports"
Set objNetwork = CreateObject("WScript.Network")
' Section which maps two drives, M: and
P: objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1 objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
' Extra code just to add a message box WScript.Echo "Map drives " &
strDriveLetter1 & " & " & strDriveLetter2
Wscript.Quit
' End of Windows Logon Script Example
Learning Points
Note 1: There are a surprising number of traps when mapping multiple drives. The central point is that each new drive letter has its own line. objNetwork.MapNetworkDrive strDriveLetter2,
strRemotePath2
Note 2: You could repeat the above line for each share you want to map, provided you change the strDriveLetter2 and strRemotePath2. Mistakes arise where people get too clever and try to map 6 drives all on one
line.
Note 3: From a scripting point of view, just create one object. It is not necessary to Set objNetwork1, objNetwork2 for each drive, just recycle the one variable -
objNetwork. Note 4: Although I disapprove, it is possible to use share names with spaces, for example, "download reports".
If you have more than two multiple drives then just copy, paste and then amend these lines: strRemotePath2 = "\\alan\downloads reports" strRemotePath3 = "\\BlueServer\Excel" strRemotePath4 = "\\RedServer\Word" strRemotePath5 = "\\GreenServer\PowerPoint"
Declare strDriveLetter3, 4, 5, just paste in extra commands to match. objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2 objNetwork.MapNetworkDrive strDriveLetter3,
strRemotePath3 objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4 objNetwork.MapNetworkDrive strDriveLetter5, strRemotePath5
You are ready to run the script.
There may be situations where you need not one, but many mapped network drives. As with many scripting jobs, there is a knack of getting the correct logic and syntax. My advice is build
your Windows VBScript gradually, master the basic logon script before attempting this more difficult example of multiple map network drives.
See Also● Logon Script Home ●
Add Error Correcting Code ● 5 Arguments of MapNetworkDrive |