Map Network drive with different credentials in command line

One of these wonderful days, I came across a need to map a network drive before I run a script. It’s a hassle to manually create the network drive mapping every time. This is because I was using different credentials to map the network drive.

Then I put my mask, and yelled “This is the job for…scripting man!!!”. Nerd

Here is my VBScript to map the network drive with different credentials without user interaction. Hope it is useful for somebody else. Make sure you type the correct server URL, drive letter and credentials in this script before you run.

‘ Script Name: MapNetwork.vbs
‘ Purpose: Map network drive with different credentials
‘ Usage: Change the values for SDrive, sNetworkLocation, sUser, sPassword
‘        variables and run the script. Script returns nothing, but it will
‘        map the network drive to the specified drive letter.

‘ Author: Anand Venkatachalapathy

Dim oNetwork
Dim sDrive, sNetworkLocation, sUser, sPassword

sDrive = "W:"
sNetworkLocation = "\MyServerData"
sUser = "MyDomainMyUserName"
sPassword = "MyPassword"

Set oNetwork = CreateObject("")

oNetwork.MapNetworkDrive sDrive,sNetworkLocation,False,sUser,sPassword

Set oNetwork = Nothing

‘******************* End of Script *************



  1. This can also be accomplished via a bat file by using the following syntax:if not exist Y: net use Y: "\\MyServer\Data" /user:MyDomain\MyUserName MyPassword


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s