Thursday, October 28, 2010

Net Use Command examples

SkyHi @ Thursday, October 28, 2010
The NET USE command is used to associate a local drive letter or device name with a shared network drive or device. Most often, the NET USE command is used for network drive mapping.
The NET USE command can be used also to disconnect a computer from a shared resource, or to display information about computer network connections.
The NET USE command also controls persistent net connections.

What network resource can I connect to using NET USE?

When connecting to a network device using the NET USE command or the NET CONNECT command, you can connect to any of the following:
  • printer LPT1 thru LPT4, 
  • serial port COM1 thru COM4,
  • AUX1 thru AUX4
  • logical drive A: thru Z:
Logical drives are most commonly referenced devices when using the NET USE command.

Difference between NET USE and NET CONNECT

The commands NET USE and NET CONNECT are interchangeable. Originally IBM introduced the NET USE command and Microsoft used the NET CONNECT command. The NET USE command is being used more often now and is the preferred method these days.

Where NET USE is used?

The NET USE command is only available on client computers, that is most often on desktop workstations. A "client computer" in this context refers to the relationship of the computer not to the physical configuration. A client computer is the one that connects to somewhere, the one that relies on the target resource. The NETWORK.COM or CLIENT.COM modules need to be loaded for this command to work.
Before you can use any network device or drive, it must have been previously shared using the NET SHARE command from the server machine.

How do I display a list of network connections on my computer?

When you use the NET USE command without parameters, NET USE retrieves a simple list of network connections. Go to your Start menu, click Run, type cmd and hit enter. Then, type NET USE and you will see a screen similar to the following output.
Status       Local     Remote                    Network
OK           H:        \\a0001-fila006-v\mpari$  Microsoft Windows Network
OK           O:        \\a0001-app9229-s\RMBech  Microsoft Windows Network
OK           P:        \\a0185-app3A43-s\QRM     Microsoft Windows Network
OK           S:        \\ho-0001-nas02\teamedm  Microsoft Windows Network
Disconnected X:        \\001-deploy1-s\mcafeedat Microsoft Windows Network
The command completed successfully.
The NET USE is very useful to get a list of connected network devices. If you need information about some particular network resource that you are connected to, you can use the following command:
NET USE [DeviceName]
This would be for example "NET USE H:" where H is your network drive.

How do I make network connections persistent (available after reboot)?

When mapping a network drive, you can tell the computer to remember your mapping after you restart the computer. If you want to make all future connections are persistent (auto-reconnect at login), use the following:
NET USE /Persistent:Yes
If you want to make all future connections non-persistent, use the following:
NET USE /Persistent:No
In this case, mapping will be lost when the computer is restarted.

How do I connect a user to his or her HOME directory?

Connecting a user to his or her HOME directory is often used in corporate setting where each user is allocated some space on the network in addition to his or her personal computer. Making this network location available every time the user logs into his or her computer can be accomplished using the NET USE command in a login script. The following is the way it works:
NET USE [devicename | *] [password | *]] [/HOME]
The devicename in this case is the HOME server/folder that is defined in Active Directory (ADUC).
In case you need to use the NET USE command to connect to a password protected file share, use the following:
NET USE [driveletter:] \\ComputerName\ShareName[\volume] [password | *]
[/USER:[domainname\]username] [/PERSISTENT:No]
The following are a few examples of this:
NET USE H: /Home
NET USE H: \\CorporateFileServer\Users\%Username%
NET USE W: \\CorporateFileServer\GroupShare /Persistent:No
Are you wondering what the /USER is?

How to specify USER in NET USE?

If you deal with enterprise security, you may need to provide user name to the NET USE command. There are two notations for giving it the user name. In the NET USE command /USER can be specified as:
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
Both work the same way.

How do I disconnect from a share using NET USE?

If you no longer need a connection to the network share, it is a good idea to disconnect from it so that it does not drain system and network resources. You can do so by using the following NET USE command:
NET USE [driveletter:] /DELETE
This should disconnect.
Important note: You cannot disconnect from a shared directory if you use it as your current drive or if an active process is using it. You can find out whether anything is using your drive by typing the NET USE [driveletter]:

Possible problem with NET USE

Mapping to a resource shared on the network using the NET USE command has some peculiarities. You can encounter a problem when trying to connect to a network share right after you map to it (when doing so in a script).
This is because the execution of the NET USE takes some time. When using the NET USE command in a script to map to a network drive, you may want to wait until the mapping has completed before continuing with further scripting commands.
START /wait NET USE [driveletter:] \\ComputerName\ShareName
The start /wait switch ensures that files can be read from the mapped drive immediately, in other words that subsequent commands in your script execute only after mapping is complete.

Syntax problem with NET USE

When using the NET USE command, you can run into some syntax-related errors. The System error 67 occurred is a very common one.
See here for more details: System error 67 has occurred.
Also, if the ServerName that you provide contains spaces, you need to use quotation marks around the text. (that would be for example "Server Name") Not providing quotation marks results in an error message: System error 85 has occurred.

Are there other related useful networking commands?

The NET SHARE command is used at the server to share a folder to others. If you want to access this shared resource from a client, you would use the NET SHARE command.
This page provides an overview of all available networking server commands: server NET commands.

NET USE syntax

The following is the syntax for NET USE:
net use
[{DEVICE | *}]
[{PASSWORD | *}]]
[{/DELETE | /PERSISTENT:{yes | no}}]
net use [DEVICE [/HOME[{PASSWORD | *}] [/DELETE:{yes | no}]]
net use [/PERSISTENT:{yes | no}]
That is about it.

Net use command connects / disconnects the computer from a shared resource, or allow to view the information about current computer connections. This command also can controls persistent network connections. If you will use net use command without any parameters, you will retrieves a list of network current connections.

net use command window

Net use command syntax:


net use [DEVICE [/HOME[{PASSWORD | *}] [/DELETE:{yes | no}]]

net use [/PERSISTENT:{yes | no}]

Net use command parameters:

DEVICE : Assigns a name to connect to the resource or specifies the device to be disconnected. There are two kinds of device names: disk drives (that is, D: through Z:) and printers (that is, LPT1: through LPT3:). Type an asterisk (*) instead of a specific device name to assign the next available device name.

\\COMPUTER\SHARE : Specifies the name of the server and the shared resource. If COMPUTER contains spaces, use quotation marks around the entire computer name from the double backslash (\\) to the end of the computer name (for example, "\\Computer Name\Share Name"). The computer name can be from 1 to 15 characters long.

\VOL : Specifies a NetWare volume on the server. You must have Client Service for NetWare installed and running to connect to NetWare servers.

PASSWORD : Specifies the password needed to access the shared resource. Type an asterisk (*) to produce a prompt for the password. The password is not displayed when you type it at the password prompt.

/USER : Specifies a different user name with which the connection is made.

DOMAIN : Specifies another domain. If you omit DOMAIN, net use uses the current logged on domain.

USER : Specifies the user name with which to log on.

DOTTEDDOMAIN : Specifies the fully-qualified domain name for the domain where the user account exists.

/SAVECRED : Stores the provided credentials for reuse.

/SMARTCARD : Specifies the network connection is to use the credentials on a smart card. If multiple smart cards are available, you are asked to specify the credential.

/DELETE : Cancels the specified network connection. If you specify the connection with an asterisk (*), all network connections are canceled.

/PERSISTENT:{yes | no} : Controls the use of persistent network connections. The default is the setting used last. Deviceless connections are not persistent. Yes saves all connections as they are made, and restores them at next logon. No does not save the connection being made or subsequent connections. Existing connections are restored at the next logon. Use /DELETE to remove persistent connections.

/HOME : Connects a user to the home directory.

net help command : Displays help for the specified net command.

Net use command Remarks:

Connecting and disconnecting from a network resource

Use net use to connect to and disconnect from a network resource, and to view your current connections to network resources. You cannot disconnect from a shared directory if you use it as your current drive or an active process is using it.

=> Viewing connection information

To view information about a connection, you can do either of the following:

=> Type net use DEVICE to get information about a specific connection.

=> Type net use to get a list of all the computer's connections.

=> Using deviceless connections

Deviceless connections are not persistent.

=> Connecting to NetWare servers

After you install and run Client Service for NetWare, you can connect to a NetWare server on a Novell network. Use the same syntax that you use to connect to a Windows Networking server, except you must include the volume you to which you want to connect.

=> Using quotation marks

If the ServerName that you supply contains spaces, use quotation marks around the text (that is, "SERVER"). If you omit quotation marks, an error message appears.

How Authentication Works for Net Use Command

When you use the NET USE command to connect to a share on a server in a domain, the following authentication process verifications take place:

=> If the client's user name is in the domain's UAS account database, the passwords are compared. If the passwords match, access is allowed to the share. If the passwords do not match, an access denied message is returned.

The behavior allows for backward compatibility with Windows for Workgroups and other clients. These clients do not pass the domain name to the Server.

=> If the client's user name does not match a user name in the domain's UAS, the domain controller checks to see if the client's domain is listed in its trust list. If the client's domain name is on the target domain's trust list, the domain controller communicates with the other domain to see if the client's user account and password are valid. If so, access is allowed to the share. If not, an access denied message is returned.

Net Use Command examples

To assign the disk-drive device name E: to the Letters shared directory on the \\Fin server, type:

net use e: \\fin\letters

To assign (map) the disk-drive device name M: to the directory Mike within the Letters volume on the \\Fin NetWare server, type:

net use m: \\fin\letters\mike

To connect the user identifier Dan as if the connection were made from the Accounts domain, type:

net use d:\\server\share /USER:Accounts\Dan

To disconnect from the \\Fin\Public directory, type:

net use f: \\fin\public /DELETE

To connect to the resource memos shared on the \\Fin 3 server, type:

net use k: "\\fin 3" \memos

To restore the current connections at each logon, regardless of future changes, type:

net use /PERSISTENT:yes

net use \\ /delete