Tip: Unmap (disconnect) network drive via command line (cmd)

When you have to disconnect your network drives you first need to know which ones of them are connected. You can run into issues (especially Windows 10 users) that your network drives do not appear under your Computer window, but when you try to connect, you will get a message that they are already connected, maybe even with a different username that you tried.

This leads you into needing to unmap the drives via command line.

How to list and unmap network drives via command line?

1. Start command prompt as administrator.

Type cmd in your search box and right click the icon, then select “Run as administrator”

run-as-administrator-cmd

 

2. Move to C disk or other location rather than staying in Windows\System32 in command line.

To navigate to C:\ disk Type cd c:\ in the cmd command line

cd-c-command-line-folders

3. Display the list of current network drives attached

Type net use and hit enter – this will display the network drives.

It is better for deleting if you output the results in a text file where you can copy the paths later.

Type net use > networkdrives.txt in the command line, then a file named networkdrives.txt will be saved to C disk (go and open it).

 

4. Unmap the drives you want to unmap.

Disconnecting a drive via command line is performed by net use. To stop / disconnect a network drive correctly, use this command

net use \\thepath\toyournetworkfolder /delete

See Microsoft Technet for all options of net use.

Tip: the path to your network folder, that you have attached as a network drive can be copied and pasted via mouse right click to command line from the txt file we generated in step 3.

Now you have disconnected the network drive.

Make sure to check again by typing net use in the command line. If the entry is gone, you have been successful.

net-use-delete-mapped-drive-network-command-line

More discussion on the subject:

http://www.pcreview.co.uk/threads/disconnect-network-drive-with-a-net-command-line-command-opposite-of-net-use.2518200/

http://superuser.com/questions/435009/how-to-remove-disconnected-drives-from-windows-explorer

http://superuser.com/questions/135752/list-mapped-network-drives-from-the-command-line-to-text-file

 

Post Author: Tom Pai

  • JediWombat

    “cd c:” sets the current path on that drive to the root; if you’re on another drive, that won’t do anything until you switch back to C:. There’s also no benefit to doing this for this operation.

    You also specify that the correct way to perform this operation is with “net stop”, then proceed to use “net use”.

    This article is a mess.

  • Toomas Pai

    Thanks for pointing that out that I’d accidentally written net stop. Of course you use net stop to stop services, not drives (updated the article).

    cd c: is to simply move to the root of C (which most users have their Windows installed and that starts as the drive they’re on in Command Prompt) that you will save the txt file with the drive paths later.

    I did my best to write an explanation that matches at least some of the configurations out there =)

  • Ruan Botha

    Thanks for this!