3.12. Mapping a Network Drive

Problem

You want to map a drive to a folder on a remote computer.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. From the menu, select Tools Map Network Drive.

  3. Beside Drive, select the drive letter you want to assign.

  4. Beside Folder, enter the UNC path to the network share you want to map.

  5. If you want the drive to be persistent, make sure the box beside Reconnect at logon is checked.

  6. By default, your current credentials will be used to access the network share, if you want to use alternate credentials, click the different username link. Enter a user name and password and click OK.

  7. Click Finish.

Using a command-line interface

The following command maps a drive to a network share point:

> net use <Drive> 
                  <Share>

The following example maps \\rtp01\myshare to the N: drive using your current credentials:

> net use N: \\rtp01\myshare

The following example maps a persistent drive using alternate credentials:

> net use N: \\rtp01\c$ /user:amer\rallen /savecred /persistent:yes

The following command lists all network connections including mapped drives:

> net use

The following command deletes the N: network drive:

> net use N: /delete

Using VBScript

' This code creates a mapped drive to a network path.
' ------ SCRIPT CONFIGURATION ------
strDrive = "<Drive>" ' e.g., N:
strPath = "<Path>"   ' e.g., \\rtp01\c$\temp
strUser = "<User>"   ' e.g., AMER\rallen
strPassword = "<Password>" boolPersistent = True ' True = Persistent ; False = Not Persistent ' ------ END CONFIGURATION ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.