Manage Network Tasks From the Windows Command Prompt
Mounting shared drives and connecting to remote resources is something you can easily do from the Windows GUI. With our quick guide to the command prompt, however, you can more easily automate large tasks.
As a network administrator, one of the Windows command line tools you should be familiar with is net use. It lets you view, create, and delete connections to shared resources from the command prompt. You can connect to shared folders and create mapped network drives.
Though you can browse to shares via Network or My Network Places, you might need to use the commands to access password-protected shares that differ from the credentials of the current logged on Windows user. These commands can also come in handy when administrating many computers, where you might find it easier to create batch files to run on PCs rather than using the Windows GUI.
If you're working on a Workgroup network, rather than a Domain network with Windows Server, make sure each PC is set to the same Workgroup name. Windows has probably set this by default to MSHOME or WORKGROUP. You can view and change this and the Computer Name of each PC by right-clicking the Computer or My Computer icon and selecting Properties.
Viewing a list of connections
First, the simplest command is to enter net use without any parameters or options. This prints a list of recent connections to shared resources on that particular computer.
Connecting to shares
Connecting to a share initiates the connection to the share. It doesn't necessarily mean you'll be able to access it. When it says "The command completed successfully" at the command prompt, it merely means the share exists and has attempted to connect.
After connecting to a share at the command prompt, you still must bring it up in Windows to access the share. You can browse through the Network or My Network Places. Alternatively, you can manually enter the UNC (Universal Naming Convention) path, such as file://server/share, into a Windows Explorer window or dialog, or even Internet Explorer.
To connect to a share using the username of the current logged in Windows user:
net use servershare
Replace server with the Computer Name of the PC and replace share with the Share Name. Here and with other commands, you can include sub-folders in the UNC path, such as file://serversharesubfoldersubfolder2">serversharesubfoldersubfolder2.
Here and with any other net use command that includes the UNC path, put quotes around the entire UNC path if the server or share name includes spaces, such as:
net use "server nameshare name"
To connect to a share with a username other than the current logged in Windows user:
net use servershare password /user:domainuser /savecred
Be sure to replace password with the actual password of the Windows user you're specifying. If you want to be prompted for the password, enter * in place of the password. In a Workgroup network, the domain is the computer name of the PC where the shared resource is located. If you prefer not to save the login credentials to the share, omit the /savecred.
Mapping shares as network drives
Mapping shares assigns a share to a drive letter in Windows. This is very useful if you need regular access to a particular shared folder. You can access the mapped network drive from the Computer window and other places displaying the drives, such as Open and Save dialogs. Instead of navigating through the Network to the share, you can select the mapped network drive, saving you a couple of clicks.
To map a share to a drive using the username of the current logged in Windows user:
net use x: servershare /persistent:yes
You can replace x with any other available drive letter. Leaving persistent set to yes means Windows will attempt to reconnect when you login again after a restart or logoff. To make this a temporary mapped drive, set persistent set to no.
If you're working on a Domain network and have Home directories defined for users, you can quickly create a mapped network drive to them:
net use x: /home /persistent:yes
To map a share to a drive with a username other than the current logged in Windows user:
net use x: servershare /user:domainuser /persistent:yes /savecred
In a Workgroup network, the domain is the Computer Name of the PC where the shared resource is located. Again, leave or set persistent to the desired setting. If you prefer not to save the login credentials of the mapped share, omit the /savecred.
Like when connecting to a share, you still must bring up mapped network drives in Windows to access them after creating the mapped drive at the command prompt. Open Computer or My Computer and you should see it appear similar to other physical drives.
Windows also provides a way to do this via the GUI. You can right-click a shared folder when browsing the network and select Map network drive….
Reconnecting mapped network drives at logon
If you omitted the /persistent:yes parameter when creating mapped network drives, you can still easily set them to reconnect at logon if you prefer. The following sets all current device connections (mapped drives) to be persistent:
net use /persistent:yes
Disconnecting shares and mapped drives
To disconnect from a share:
net use servershare /delete
To disconnect and remove a mapped network drive:
net use x: /delete
You can also disconnect from mapped network drives via the Windows GUI: simply right-click a mapped drive and select Disconnect.
To disconnect all shares and mapped network drives:
net use * /delete /y
You can omit the /y to get a confirmation of which shares will be deleted.
Points to remember
We've reviewed all the main functions net use provides. Connecting and accessing shares is rather simple but can cause a major headache if you run into problems. Be sure the firewalls are set to allow sharing. Make sure you're on the same Workgroup if you aren't on a Domain network. Remember to use quotes around UNC paths that contain spaces. If you can't access and/or write to a share, be sure review the Sharing and File Permissions of the shared folder.
Eric Geier founded NoWiresSecurity, which helps small businesses quickly and easily protect their Wi-Fi with enterprise-level security. He's also a freelance tech writer and author of many networking and computing books, for brands like For Dummies and Cisco Press.