WshNetwork.MapNetworkDrive
Add a shared network drive mapping.
Syntax WshNetwork.MapNetworkDrive(strLocalDrive, strRemoteShare, [persistent], [strUser], [strPassword]) Options: strLocalDrive : The drive letter (e.g. L:) strRemoteShare : The UNC path to the remote drive \\MyServer\MyPrinter (String value) persistent : True/False - store the mapping persistently in the users profile default = false strUser : The user name. (Optional) strPassword : The password. (Optional)
Examples
Dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
strLocalDrive = "H:"
strRemoteShare = "\\myserver\users"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, False
The example script below takes this a stage further, disconnecting the drive letter first (and coded to cope with persistent and/or disconnected drive shares)
DriveMap.vbs - Connect a local drive letter to a remote file share
For workgroup machines sharing files via pass-thru authentication with no domain login script, a persistent drive map can be used. Persistent drives will automatically connect to the resource whenever it is available.
"The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side" - James Baldwin
Related commands:
NET, list drive mappings - WshNetwork.EnumNetworkDrives
NET, remove drive map - WshNetwork.RemoveNetworkDrive
Q138365 - Autodisconnect (Red cross)
Q305355 - Drives disconnected, and a red "X" appears
Equivalent Windows command:
NET - Manage network resources