My career as an IT professional has been filled with reminders that almost everyone I interact with is much younger than I. One advantage I gain from my age and my long history with computers is an automatic reflex to use command-based tools whenever I have to perform a task. Often, when I interact with administrators who are struggling to create complicated scripts, I can't resist saying, "A batch file would be easier, quicker, and work just as well." I get some strange looks, because so many administrators are too young to have had experience with DOS, and they aren't quite sure what a batch file is. (I tell them a batch file is simply a text file containing DOS commands.) Whenever I write about batch files, I get a ton of email asking for more information about creating and using these handy utilities.
Mapping Drives from the Command Line
Most of the queries I receive from administrators ask about mapping drives throughout the network to make sure users access the appropriate folders on remote computers. (These admins often add that they try to script the solution but find the task more work than they anticipated.) They also want to know if there's a secret to mapping a drive to a folder that isn't shared. The answer to both questions is to use the command line.
You can map drives from the command line with the Net Use command. Type
net use
with no switches at a command prompt and you'll receive information about the currently mapped drives that also lets you know which drive letters are available. The following information displays:
- The current state of the Reconnect at Logon option, specified either by the text "New Connections Will Be Remembered" or "New Connections Will Not Be Remembered."
- The current status of each connection, specified either by OK (which means connected) or Disconnected.
- The drive letter.
- The mapped folder's name in Universal Naming Convention (UNC) format.
- The network type (usually Microsoft Windows, but if you're running Novell NetWare client software and mapping drives to a NetWare server, the network listing is NetWare).
Usually, mapped drives are marked Disconnected when you first boot the computer, but as soon as you access the mapped drive its status automatically changes to Connected. You can access the mapped drive in My Computer or by entering the drive letter in the command window, as follows:
k:
Don't forget the colon.
Creating a Mapped Drive
To map a shared folder to a drive letter, enter on the command line
net use d: \\<computername>\<sharename>
Substitute the drive letter you want to assign to the share for d. If any folder in the path has a name that includes a space, enclose the entire path, including the opening double backslash, in quotation marks. Windows returns the message The Command Completed Successfully. If you're a skeptic, use the Net Use command to make sure your new mapped drive appears in the list the command returns.
Whether or not your new mapping reconnects at logon depends on the current state of the Reconnect at Logon option. You can set the reconnection option you prefer with the /persistent: [yes/no] switch. For example, to reconnect at logon, enter
net use f: \\<computer\share>/persistent: yes
To map a drive for the current session only, enter
net use f: \\<computer\share> /persistent: no
The reconnection option you select becomes the default state of the Reconnect at Logon option (including the option displayed on the GUI version of the Map Network Drive dialog).
Mapping Drives to Unshared Folders
Unlike the mapping function in the Windows GUI, the Net Use command doesn't limit you to mapping shared folders. To map an unshared subfolder of a shared folder or any folder on a shared drive, enter on the command line
net use f:
\\<computer>\<sharename>\<subfoldername>
The ability to map a resource that isn't explicitly shared is useful because you can share a drive, then map any or all of the folders on that drive. Of course, you must be judicious about security in such an environment, so make sure the permissions in the target unshared folder are set appropriately.
Removing a Mapped Drive
To remove a mapped drive, enter
net use <d>: /delete
substituting the appropriate drive letter for d. The system returns the message
d: was deleted successfully
Batch Files for Mapping Drives
The Net Use command gives you the ability to use batch files to create mapped drives. Administrators can use logon batch files that contain the Net Use command to set mapped drives for users. Mapped drives make it easy for users to access the appropriate folders for specific software and data. For example, for users who work in the company database, you might have a logon script with the following contents:
net use g: \\<DBServer<\<OurDatabase>
net use h: \\<DBServer>\<DatabaseFiles>
Name the file whatever you want (it must have a .bat extension), and copy it to the logon script directory on your domain controller (DC). The default location for logon scripts on a DC is %SystemRoot%\ SYSVOL\sysvol\<domainname.com>\scripts. The scripts subfolder is automatically shared with the share name NETLOGON (which is the name that appears on remote computers when you expand the DC in My Network Places).
Be careful not to map the drive letter that's in use for User Home Drives. During user logon, Windows maps the home drive first, before running any logon scripts from the scripts subfolder. If your logon script tries to map a drive letter that's already used, the system returns the error The local device name is already in use.
Prev. page  
[1]
2
3
4
next page