metinsaylan // rogue developer

Mapping shared folders as network drives using VBsript

//

If you are working on a file-server, you will need a better way to share folders: that is Network drives. In our design office, We are using a shared folder on our file server. * That folder is added to our PCs as a network drive using the **vbscript below:

Option Explicit
On Error Resume Next

Dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
Dim strDomain, strUser, strPass
Dim mapDriveLetter, mapServerPath

' Setup User Connection Variables
strDomain = "NETWORKDOMAIN_OR_SERVER_HOSTNAME"  ' objNetwork.UserDomain
strUser = "your_user_name_or_server_admin_account" ' objNetwork.UserName
strPass = "your_password_or_server_admin_password"

' Remove Previously Mapped Drives
objNetwork.RemoveNetworkDrive "M:", True, True
objNetwork.RemoveNetworkDrive "N:", True, True
objNetwork.RemoveNetworkDrive "R:", True, True

' Map New Network Drives
mapDriveLetter = "M:" ' Change drive letter as you wish
mapServerPath = "\FILESERVERSharedFolderName" ' This is server we are connecting to

objNetwork.MapNetworkDrive mapDriveLetter, mapServerPath, True, strDomain & "" & strUser, strPass

' Setting custom username & password for other mapped drives (Remove if not needed)

strDomain = "SERVER2_HOSTNAME"
strUser = "Administrator"
strPass = "AdminPassword"
mapDriveLetter = "N:"
mapServerPath = "\SERVER2_HOSTNAMESharedFolderOnServer2"

objNetwork.MapNetworkDrive mapDriveLetter, mapServerPath, True, strDomain & "" & strUser, strPass
```


After you save this file as connect.vbs, you can run it by double clicking. 
It may take a few seconds to connect to server, if it doesn't please double check username and passwords.
Search Mapping shared folders as network drives using VBsript on Google