Share via


VBScript: Map network drives on logon

Need to create logon scripts that would automatically map network drives for users as they logon?
The process is quite simple if you adopt a simple vbscript to connect the required printers and then apply a group policy that would run the script during logon.

Below is a simple script that will do what we require (remember save it as .vbs to run):

' Script to map network drives during user logon

On Error resume Next ' very important otherwise users will get errors on subsequent reconnections

' Create the object that creates the mapped drives
Dim MAP_Connection

' Create our variables to hold mapped network drives
Dim MAP_Location_1, MAP_Location_2

' Create variables for each drive letter
Dim Drive_1, Drive_2

' Initialise our printers
MAP_Location_1 = "\file-server\share_1"
MAP_Location_2 = "\file-server\share_2"

' Initialise the printer connections object
Set MAP_Connection = CreateObject("WScript.Network") 

' Let's map the drives
MAP_Connection.MapNetworkDrive Drive_1, MAP_Location_1
MAP_Connection.MapNetworkDrive Drive_2, MAP_Location_2 

WScript.Quit