Windows Logon Scripts – Multiple MapNetworkDrive

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

 ♦

Mapping Multiple Drives Scenario:

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.

Example – MapNetworkDrive to Multiple Drives

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

  1. On Line 15 change the server name from ‘\\alan’ to your server name.
  2. 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

  1. Copy and paste the script below into notepad.
  2. Change the server name from "\\alan to the name of your server.
  3. Make sure that you have not one, but two network shares on your server.
  4. Save the file with .vbs extension e.g. MNDMultiple Drives.vbs.
  5. 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 https://computerperformance.co.uk/
‘ Version 1.6 – April 24th 2010
‘ —————————————————-‘
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

Solarwinds Config GeneratorGuy Recommends: The Free Config Generator

SolarWinds’ Config Generator is a free tool, which puts you in charge of controlling changes to network routers and other SNMP devices.  Boost your network performance by activating network device features you’ve already paid for.

Guy says that for newbies the biggest benefit of this free tool is that it will provide the impetus for you to learn more about configuring the SNMP service with its ‘Traps’ and ‘Communities’. Try Config Generator now – it’s free!

Download your free copy of Config Generator

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".

More Than Two Drives?

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.

Window 8 Group Policy Drive MapsGroup Policy Map Drive

The modern group policy method of drive mapping does not require any scripting.  In Windows Server 2008 you can launch the Group Policy Management Console and configure Drive Maps by clicking with a mouse.  See more on Windows 8 Group Policy Drive Maps.

Multiple Mapped Network Drives Summary

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.

 

Download my Logon Script eBook for only $6.25

Logon ScriptThe extra features you get in your eBook include, more pages full of detailed examples.  Also, ten ‘how to…’ sections, with screen shots showing which menus to use.  Go for Guy’s eBook – and get a printable version with copy enabled and no expiry date.

  Jumbo Script 7 Package

If you like this page then please share it with your friends

 


See more logon scripts examples

Logon Script Home   •EnumNetworkDrives   • Map Network Drive Group   • Free Import CSV Tool

Map Network Drive Script   • Vbscript Map Network Drive Username   • Map Multiple Network Drives

ObjNetwork.MapNetworkDrive   • Disconnect Network Drives   • Logon script group policy