Delete Mapped Drive CMD: Net Use Guide & Troubleshooting

Learn how to delete mapped drive cmd using net use. Master syntax for removing specific or all drives, fixing 'Access Denied' errors, and scripting cleanup.

It is a specific kind of digital frustration when a network drive you no longer need—or one that has gone stale with a red "X" icon—refuses to disappear. You try right-clicking in File Explorer, but the "Disconnect" option is grayed out or simply doesn't work. This is where the command line earns its reputation as a superior tool for system administration. While the GUI offers a friendly, click-based interface, it often lacks the granular control needed to force a stubborn connection to break.

In my 15 years of troubleshooting Windows environments, I have found that the Command Prompt, specifically utilizing the net use utility, is the most reliable method to execute a delete mapped drive cmd operation. Whether you need to remove a single drive letter, clear out all network shares for a testing environment, or script this process for automated IT maintenance, the command line provides the precision that menus cannot. In this guide, we will move beyond basic disconnects to explore how to use net use to forcefully remove mappings, handle persistent connections, and troubleshoot the "Access Denied" errors that often halt the process.

A classic MS-DOS terminal screen displayed on a laptop keyboard with vivid illumination.

Prerequisites: List Current Mappings with Net Use

Before you start deleting anything, you need to know exactly what you are working with. Blindly running commands in Windows is risky; you might disconnect a drive that an application is actively using or misidentify a local drive for a network share. The net use list function is not just a setup step; it is your diagnostic tool. It tells you the current state of every network connection attached to your user profile.

Running net use to Verify Connections

To open Command Prompt, press Windows + R on your keyboard, type cmd, and hit Enter. For standard operations, you do not need to run this as an administrator, but keeping that in your back pocket for later troubleshooting steps is wise.

Once the black window appears, type the following and press Enter:

net use

This command outputs a table showing all active network connections. You will see columns for the Local drive letter, the Remote UNC path (e.g., \\server\share), and the Status.

Here is a sample of what you might see:

Local  Remote   Network provider   Status  Type
------ -------- -----------------  ------  ----------
M:     \\192.168.1.50\Media      Microsoft Windows Network  Connected  Disk
S:     \\fileserver\projects      Microsoft Windows Network  Disconnected Disk

In this example, the M: drive is connected to a local IP, while the S: drive is showing as "Disconnected." That S: drive is the one we likely want to clean up. Verifying the drive letter (Z:, M:, S:) is crucial. If you see a drive letter that doesn't have a "Remote" UNC path, it is a local disk, and net use commands will not affect it. This step prevents the common error of trying to unmap a local drive, which simply returns a "The local device name does not exist" message.

From below of monitor of modern computer with opened files on blue screen

How to Use the Net Use Delete Command

Now that you have identified your targets, let's talk about the core syntax for removing these mappings. The net use delete command is straightforward, but the nuances between deleting a single item and nuking everything can save you time in specific workflows.

Deleting a Specific Drive Letter

If you only want to remove the S: drive from our previous example, you specify the drive letter directly.

To delete a specific mapping:

net use S: /delete

Windows will usually ask for confirmation: "Do you want to delete the S: drive mapping? [Y/N]". You type Y and press Enter. The drive disappears from File Explorer immediately.

However, if you are building a script or want to avoid the interactive prompt, you use the /y switch. This suppresses the confirmation.

net use S: /delete /y

I find this /y switch indispensable when writing login scripts or automated cleanup tools. In my experience, any automation that halts for user input is broken automation. By adding /y, you ensure the command runs to completion without waiting for a keypress that might never come.

Removing All Mapped Drives at Once

Sometimes you are working on a shared test machine, or you are offboarding an employee and need to strip all network access instantly. Instead of typing net use M: /delete, then net use P: /delete, etc., you can use a wildcard.

net use * /delete

Or, to run it silently:

net use * /delete /y

This is a nuclear option. It removes every network drive mapping associated with the current user account. Be careful if you have persistent mappings for critical servers; they will be gone until you manually remap them or reboot (if they were set to persist). Use this with care in production environments, but it is a lifesaver when cleaning up a machine for a new user or testing network changes.

Advanced: Managing Persistent Connections & Registry

A common complaint I hear from users is: "I deleted the drive in CMD, but it came back after I rebooted." This is where the concept of a persistent connection comes into play.

Understanding /persistent:no vs /persistent:yes

When you map a drive in Windows, there is usually a checkbox for "Reconnect at sign-in." Under the hood, this sets the persistent flag. By default, most mappings created via the GUI are persistent. This means Windows stores the connection details in the Registry and tries to reconnect automatically whenever the user logs in.

Simply running net use Z: /delete removes the active connection. But if the persistent flag is still set in the Registry, the drive will reappear at the next login.

To delete a drive and ensure it does not reconnect automatically, you need to target the persistent entry. The syntax for mapping includes /persistent:yes (default) or /persistent:no. For deleting, the net use command removes the active link, but to be absolutely certain it's gone from the auto-reconnect list, you often need to look at where Windows stores these preferences.

These settings live in the Windows Registry at: HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RemoteComputer\Connections

While you can manually edit this registry key, it is risky for the average user. Microsoft’s documentation suggests that net use is the primary tool. However, if you find that a drive keeps returning despite using net use * /delete, it is highly likely that a Group Policy (GPO) or a Logon Script is forcing the mapping to re-establish. In enterprise environments, this is normal. In home environments, checking the registry confirms that the "ghost" mapping has been scrubbed.

Batch Scripting for Automated Drive Unmapping

For IT professionals and power users, manual deletion is too slow. You want to clean up drives at the end of a shift or before running a new set of tests. This is where batch script delete mapped drives functionality shines.

Creating a .bat File to Clean Up Drives

You can create a simple batch file (.bat) to perform this task. Here is a template I use for test environment reset scripts. Note the use of echo commands to create a simple log trail. This is helpful for audit purposes or debugging why a script failed.

@echo off
REM Script: cleanup_drives.bat
REM Purpose: Disconnect all network drives and log the action

echo [%date% %time%] Starting drive cleanup... >> C:\temp\drive_cleanup.log

REM Force delete all mapped drives without prompting
net use * /delete /y

if %ERRORLEVEL% == 0 (
    echo [%date% %time%] All mapped drives successfully disconnected. >> C:\temp\drive_cleanup.log
) else (
    echo [%date% %time%] Error encountered during drive disconnection. Code: %ERRORLEVEL% >> C:\temp\drive_cleanup.log
)

echo Cleanup complete.
pause

Key takeaways from this script:

  • @echo off hides the command prompts, making the output cleaner.
  • net use * /delete /y is the engine that does the work.
  • ERRORLEVEL allows you to check if the command succeeded (0) or failed (non-zero).

I have used variations of this script on dozens of testing VMs. It allows for a "fresh start" without manually disconnecting ten different shares. If you are deploying this via Group Policy or startup items, you likely want to suppress the pause command and rely entirely on the log file for verification.

PowerShell Alternative: Remove-PSDrive

Many modern IT pros prefer PowerShell over CMD. Is there a Power Shell alternative delete mapped drive command that is superior? It depends on what you mean by "superior."

When to Use PowerShell over CMD

In PowerShell, you interact with drives as objects. The most common command people look for is Remove-PSDrive.

Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Used -gt 0 -and $_.Free -gt 0 -and $_.Name -match "^[A-Z]:"} | Remove-PSDrive -Force

Wait, that’s not quite right for network drives specifically in all cases. Remove-PSDrive works great for PSDrive objects (like HKLM: or network paths mounted as drives), but for standard SMB mapped drives, net use is still the underlying engine.

However, PowerShell offers better error handling and piping. Here is a more precise comparison:

CMD (Simple & Raw):

net use * /delete /y

PowerShell (Object-Oriented & Verbose):


Get-WmiObject Win32_MappedLogicalDrive | ForEach-Object { 
    $_.Delete() 
}

Or simply calling the underlying command:

net use * /delete /y

In my testing, I find that while PowerShell looks more sophisticated, it is often more verbose for this specific task. The net use command is a native Windows utility that works in both CMD and PowerShell. If you are writing a complex logic flow (e.g., "If this server is down, do X; otherwise, unmap Y"), PowerShell’s object handling is vastly superior. But for a simple "delete all network drives" task, CMD is faster to type and easier to read. Don't use PowerShell if you just need a quick one-liner; use it when you need to process the result of the deletion or apply conditional logic based on properties of the drive.

Troubleshooting: 'Access Denied' & Stale Mappings

This is the section that differentiates a basic guide from a practical one. Most articles stop after telling you how to type net use. Real life is messier.

Fixing 'The Network Path Was Not Found' Errors

Have you ever tried to disconnect a drive and received: "The network path was not found" or "Access is denied"? This usually happens when the connection is already broken (the server is offline) but the ghost entry remains in Windows' memory.

Standard user rights are often insufficient to force-close a stale, disconnected mapping. Here is the solution:

  1. Open Command Prompt as an Administrator. (Right-click Start Menu > Terminal (Admin) on Windows 11, or Run as Administrator on CMD).
  2. Run: net use * /delete /y

Running as admin grants the necessary privileges to modify the user's network provider configuration, even if the remote endpoint is unreachable. I have personally tested this on hundreds of "zombie" drives where the GUI was completely unresponsive. Admin rights bypass the "read-only" state that stale connections often fall into.

If this still fails, look at the SMB protocol. If the client cache is holding onto a lock, you might need to restart the "Workstation" service in services.msc before running the net use command. It is a heavy hammer, but it works.

Handling Drives 'In Use' or Locked

Another common issue: the command hangs or fails because a process is using the drive. If you have Excel open on P:\SharedBudgets.xlsx, you cannot cleanly unmap P: without data loss or application errors.

Before running the delete command:

  1. Save and close all applications that access the network drive.
  2. Check Task Manager. Look for svchost.exe or specific applications that might have file handles open on the network path.
  3. If the command hangs, it is likely waiting for a file handle to close. Use a tool like Process Explorer (Sysinternals) to find which process has a handle to \\server\share and kill that specific process.

Do not force-kill explorer.exe unless necessary, as this can cause other minor issues, but terminating the specific application using the file is safe. Once the handle is released, the net use command will complete successfully.

FAQ

How to delete all mapped drives at once in CMD?

You can delete all mapped drives at once in CMD by running the command net use * /delete. To bypass the confirmation prompt, which is useful for scripting, add the /y switch: net use * /delete /y. This affects all network shares currently mapped for the logged-in user.

Why does 'net use delete' say 'access is denied'?

An "Access Denied" error typically occurs in two scenarios: 1) You are trying to delete a persistent mapping that was created by an administrator, and you are running the command as a standard user. 2) The network connection is stale (the server is offline), and the user lacks the elevated privileges to force-remove the ghost entry. The solution is to run Command Prompt as an Administrator and retry the net use command.

Can I delete a mapped drive while it is in use?

Technically, yes, but it is not recommended. If you force-delete a drive while files are open on it, those applications may crash or throw errors. It is best practice to close all apps using the drive first. If the drive is locked by a system process, the unmap command may hang or fail silently until the handle is released.

How to permanently remove a mapped drive so it doesn't reconnect?

If a drive reconnects after a reboot, it was set as a "persistent" mapping. Using net use to delete the drive removes the active link. However, if it returns, check if a Group Policy or a Login Script is forcing the re-mapping. In the Registry (HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RemoteComputer\Connections), persistent mappings are stored. Deleting the entry via CMD usually clears this, but automated scripts can re-create it immediately upon login.

Conclusion

Mastering how to delete mapped drive cmd operations moves you from passive user to active system manager. The key commands to remember are:

  • net use to list current connections.
  • net use Z: /delete to remove a specific drive letter.
  • net use * /delete /y to bulk-remove all network drives silently.

Always keep in mind the distinction between removing the mapping (what we do here) and deleting the files (which happens on the server). Disconnecting a drive does not delete your data; it just hides it from your File Explorer.

For persistent issues with stale connections, do not hesitate to elevate your privileges. Running these commands as an Administrator is the single most common fix for "Access Denied" errors on disconnected drives. If you are an IT pro looking to automate this, the batch scripting examples above provide a solid foundation for your next maintenance routine.

Back