0

The following script, found on the web, works wonderfully to map a network drive within Windows 7.

What I'd like to do is add yet another mapped drive within the same script, but am unfamiliar with VBS scripting and am thus seeking your expert advice!

Thanks a bunch!

Dan

' MNDArguments.vbs
' VBScript to map a network drive with all 5 arguments. 
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.3 - April 24th 2010
' ---------------------------------------------------------' 
Option Explicit
Dim objNetwork 
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile

' Values of variables set
strDriveLetter = "H:" 
strRemotePath = "\\alan\home" 
strUser = "guytom"
strPassword = "P@ssw0rd1"
strProfile = "false"

' This section creates a network object. (objNetwork)
' Then apply MapNetworkDrive method. Result H: drive
' Note, this script features 5 arguments on lines 21/22.
Set objNetwork = WScript.CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword 

WScript.Quit

' End of Example script .
1
  • @KenWhite yup, I tried that but I must have the syntax/logic wrong... Commented Apr 10, 2013 at 22:54

2 Answers 2

2

After you map the first drive, change the variables to the second location, use a different drive letter in strDriveLetter, and call objNetwork.MapNetworkDrive again.

strDriveLetter = "H:" 
strRemotePath = "\\alan\home" 
strUser = "guytom"
strPassword = "P@ssw0rd1"
strProfile = "false"

' This section creates a network object. (objNetwork)
' Then apply MapNetworkDrive method. Result H: drive
' Note, this script features 5 arguments on lines 21/22.
Set objNetwork = WScript.CreateObject("WScript.Network") 
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword 

strDriveLetter = "I:"
strRemotePath = "\\Some\Network\Path"
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword 

(This really should have been something you could figure out by reading the code you posted, even if you are not familiar with VBScript.)

Sign up to request clarification or add additional context in comments.

1 Comment

aha, that did it -- I had tried other variations on this but not the one you suggested. Thanks for being patient with me! Cheers.
2
Option Explicit
Dim objNetwork, i
Dim strDriveLetter, strRemotePath, strUser, strPassword, strProfile

Dim arrDrives(1,4)
arrDrives(0, 0) = "H:" 
arrDrives(0, 1) = "\\alan\home"
arrDrives(0, 2) = "guytom"
arrDrives(0, 3) = "P@ssw0rd1"
arrDrives(0, 4) = "false"

arrDrives(1, 0) = "I:" 
arrDrives(1, 1) = "\\tom\home"
arrDrives(1, 2) = "tomguy"
arrDrives(1, 3) = "P@ssw0rd1"
arrDrives(1, 4) = "false"

For i = 0 To UBound(arrDrives)
    Set objNetwork = WScript.CreateObject("WScript.Network") 
    objNetwork.MapNetworkDrive arrDrives(i, 0), arrDrives(i, 1), _
    arrDrives(i, 4), arrDrives(i, 2), arrDrives(i, 3) 
Next

WScript.Quit

Copy/paste arrDrive(0,0) to (0,4) to add another drive. Don't forget to change Dim arrDrives(number of drives minus 1, 4).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.