.MapNetworkDrive

Add a shared network drive mapping.

Syntax 
      objNetwork.MapNetworkDrive(strLocalDrive, strRemoteShare, [persistent], [strUser], [strPassword])

Key
   objNetwork     : A WScript.network object

   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)

Example

Dim objNetwork, strLocalDrive, strRemoteShare
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:

NET, list drive mappings - .EnumNetworkDrives
NET, remove drive map - .RemoveNetworkDrive
Q138365 - Autodisconnect (Red cross)
Q305355 - Drives disconnected, and a red "X" appears

Equivalent Windows CMD command: NET - Manage network resources


© Copyright SS64.com 1999-2013
Some rights reserved