map multiple network drives using VB script

Submitted by admin on Wed, 11/11/2009 - 09:07

It’s possible to create VB script that maps more than one drive at the time.

1. copy this script and paste it to a text file:
----------------------
Option Explicit
Dim objNetwork, strShare1, strShare2
Dim strDrive1, strDrive2
strDrive1 = "P:"
strDrive2 = "R:"
strRemotePath1 = "
\\MyServer\Public"
strRemotePath2 = "
\\MyServer\reports"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDrive1, strShare1
objNetwork.MapNetworkDrive strDrive2, strSahre2
Wscript.Quit
-----------------------
Explanation:
Dim objNetwork - Creating a Network Object to populate the new drives
Dim strShare1, strShare2 - Prepare a new string for two network drive letters
Dim strDrive1, strDrive2 - Prepare a new string for two network Paths
strDrive1 = "P:"  - populate P: into string
strDrive2 = "R:" - populate P: into string
strRemotePath1 = populate the first drive path
strRemotePath2 = populate the second drive path
objNetwork.MapNetworkDrive strDrive1, strShare1 - maps P: to connect to
\\MyServer\Public
objNetwork.MapNetworkDrive strDrive2, strSahre2 - maps R: to connect to
\\MyServer\reports

2. Rename the text file to .VBS extension.
3. Run the scripts and check "My computer" if drives P: and R: created.
4. Put this File into GPO Object to enroll it for your organization.