Lately, in this column, I've been examining Windows Server 2003's and Windows XP's built-in command-line networking tools. This time, I want to look at the one Net command that just about everyone knows: Net Use. You might think you know the Net Use command, but I bet you'll be surprised to learn what it can do.
The basic Net Use command tells your workstation to log you on to a given file server and grant you access to a particular share via a drive letter. The command
net use N: \\myserver\stuff
tells your workstation to contact the myserver system, grant you access to a share on that server called \stuff, and create an imaginary drive N, through which you can access the data on that share. Now, let's start our in-depth look at Net Use with three quick enhancements to that example.
First, Net Use lets you specify the file server's name in ways other than the basic host name (e.g., myserver). You can also use a fully qualified DNS name, such as myserver.bigfirm.com, or an IP address, such as 10.50.50.66. Second, you needn't specify a drive letter; if you simply type an asterisk (*), Net Use will choose a drive letter from the unused letters. Third, you can tell Net Use to connect you not to the whole share but to a folder within a share. For example, suppose your home directory is on myserver, in a share named \homedirs, in a folder named \georgehome. You could map drive letter H directly to the \georgehome folder by typing
net use H: \\myserver\homedirs\georgehome
Instead of opening the H drive and seeing the entire list of home directory folders, you'd see only the contents of your folder. Speaking of home directories, Net Use's /home option lets you map to a user's home directory:
net use H: /home
You don't need to specify a server or share. Net Use looks up that account's home directory. Unfortunately, however, Net Use /home won't reach to a folder in a share.
Of course, logging on to any server involves credentials. I haven't entered any here because I'm assuming whoever issues the Net Use command is already logged on with sufficient credentials. But that's not always the case, and so we have the /user (/u) option. If the \stuff share on myserver is available only to the mary user account, with password swordfish, I could connect to the share without having to log out and log back on as Mary:
net use * \\myserver\stuff /u:mary swordfishIf I don't want to type the password in clear text, I can type an asterisk in place of the password, and my computer would prompt me to type the password—and it wouldn't echo the characters to the screen.
If you're connecting to resources inside a domain, you won't usually have to type in user credentials. But if you must regularly connect to a server that isn't part of your domain—for example, if you need to connect to a Web server—it can get downright irritating to have to continually type in your username and password. For this reason, Windows 2003 and XP offer the Net Use option called /savecred. If you type
net use * \\mywebserver\contentroot /savecred
Net Use will prompt you for credentials, then remember them. Your workstation will then proffer that name and password whenever you log on to that server.
Learn to Share
When you type the Net Use command by itself, you can get a quick look at all the shares you're connected to. You can disconnect from any share by identifying the share and using the /delete (/d) option. You can disconnect from all your shares by typing
net use * /d /y
where the asterisk specifies all shares, the /d option disconnects from the share, and the /y option prevents Net Use from stopping and asking, "Are you sure?"
Net Use also lets you control whether to reconnect to a share every time you log on. By default, if you use Net Use to access a particular share, use that share for a bit, then log off and go home, your system will reconnect you to that share when you log on the next morning. If I want Net Use to not reconnect to shares by default, you can type
net use /persistent:no
But what if you want a particular share to be persistent anyway? Then, you'd just add /persistent:yes to the end of the Net Use statement that connects you to that share.