You’re sitting at your desk, trying to disconnect a mapped drive that’s acting up—maybe it’s pointing to a server that changed IP addresses, or perhaps you just want to clean up old links before reconfiguring your network. You type the command, hit enter, and nothing happens. Or worse, you force it, and now you’ve lost access to a file you hadn’t saved yet. This is the classic frustration with managing network shares in Windows: the Graphical User Interface (GUI) is often too slow, while command-line tools can feel like defusing a bomb without a manual.
I’ve spent the last fifteen years wrestling with network infrastructure and Windows administration. I remember the days when net use was the only way to manage shares on a local area network (LAN). Today, it remains the most precise tool for controlling how your system connects to remote shares. In this guide, we’ll move beyond the basic "connect" tutorial. We will focus entirely on the net use disconnect mapped drive process, including how to handle stubborn connections, automate bulk deletions, and fix those annoying "ghost" icons that haunt your File Explorer.
Mastering Net Use Command Syntax for Disconnections
Basic Syntax: Removing a Single Drive
The foundation of all this is understanding the structure of the net use command. When you want to remove a specific drive letter, say Z:, which is mapped to a shared resource on your server, the syntax is straightforward. You tell the system which remote path or drive letter you are targeting and append the /delete flag.
Many users confuse /disconnect with /delete. In the context of removing a mapped drive, they are functionally synonymous, but /delete is the standard, documented parameter for removing the mapping from your system. Using the correct flag ensures compatibility across different Windows versions.
To remove the drive letter Z:, open your Command Prompt (preferably as Administrator to avoid permission errors) and type:
net use Z: /delete
If you want to be concise, Windows also accepts the shorter /d flag:
net use Z: /d
I often recommend running the net use command with no parameters first. This lists all current connections. This quick audit helps you confirm that Z: is actually the drive you think it is before you delete it. It’s a small habit, but it prevents you from accidentally removing a critical shared folder during a migration.
Deleting Connections Without Drive Letters
Sometimes, you’ll encounter connections that don’t have a drive letter assigned. This happens often with administrative shares like C$ or IPC$, or when a user connects to a UNC path (Universal Naming Convention) directly without mapping it to a letter. These "transient" connections can linger in your session, clogging up your resource list.
To target these, you use the full UNC path instead of a drive letter. For example, if you have a stale connection to \\FileServer01\PublicDocs that isn't assigned a letter, you can delete it directly.
net use \\FileServer01\PublicDocs /delete
This is particularly useful in scripting environments where you don’t want to pollute the drive letter space. By targeting the UNC path directly, you ensure you’re removing the specific connection resource without affecting any other mappings that might be using different paths to the same server.
Advanced Techniques: Force, Persistent, and Batch Scripts
Using /Force and /Yes Parameters
Here is where it gets tricky. If you try to disconnect a drive that has active files open, Windows will throw an error saying the device is busy. In those cases, you need the /force parameter. However, I must emphasize: use this with extreme caution.
When you use /force, you are telling Windows to close all handles to that share immediately. If a user has an unsaved Word document open on that drive, that file will likely be corrupted or lost. I’ve seen IT teams force-disconnect shared drives during a maintenance window only to have developers realize they lost two hours of code because the editor had a lock on a file.
The /force flag bypasses the "file in use" check. Combine it with /yes (or /y) to suppress the confirmation prompt, which is essential for automation scripts.
net use Z: /delete /force /yes
The /yes parameter ensures that the command doesn’t pause waiting for you to hit "Y" at a prompt. This is critical when you are running a script that cycles through multiple drives. Without it, your batch file will hang indefinitely, looking for user input that will never come in an unattended context.
Batch Scripting to Disconnect All Drives
Manual disconnecting is fine for one or two drives. If you are an administrator managing dozens of workstations, or perhaps a developer switching between different project environments, you need automation. The most common request I see is "how do I wipe all my mapped drives at once?"
You can achieve this with the wildcard *. However, simply running net use * /delete will still prompt you for confirmation for each drive. To silence this, you add /y.
Here is a more robust batch script approach that iterates through drives and disconnects them specifically, allowing you to log the process or add error handling:
@echo off
echo Disconnecting all mapped drives...
for /f "tokens=2 delims=:" %%i in ('net use ^| findstr /r /c:"^[A-Z]:"') do (
echo Deleting %%i:
net use %%i: /delete /y
)
echo Cleanup complete.
In most standard maintenance scenarios, however, the one-liner is sufficient and much faster:
net use * /delete /y
I typically use this command before applying new Group Policy objects that push new mappings, or before running a network diagnostic tool that requires a clean state. It ensures that no old, broken links from a previous shift are interfering with the new configuration.
PowerShell Alternatives for Modern Administration
Remove-SmbMapping Cmdlet
While net use is a veteran tool, it has its limitations. It’s string-based, not object-based. If you want to inspect properties of a connection before deleting it, or if you want to pipe the results into another command, PowerShell is the better choice.
PowerShell provides the Remove-SmbMapping cmdlet for permanent mappings and Remove-PSDrive for transient ones. For most mapped drives that you created via the GUI or net use, Remove-SmbMapping is the correct tool.
First, let’s list your mappings to see what we’re working with:
Get-SmbMapping
To remove a specific persistent mapping, say drive Z:, the command is clean and direct:
Remove-SmbMapping -LocalPath "Z:" -ErrorAction SilentlyContinue
The advantage here is error handling. With net use, if the drive isn't connected, you get a generic error code. In PowerShell, you can specify how errors are handled. The -ErrorAction SilentlyContinue parameter is a lifesaver in scripts where you know some drives might already be disconnected. It prevents the script from breaking.
Moreover, PowerShell allows you to filter. For instance, if you only want to disconnect drives that are currently in an "Offline" state, you can pipe Get-SmbMapping to Where-Object. This level of granularity is simply not available in the classic CMD syntax. If you are building a management dashboard or a self-service portal for your users, the PowerShell approach is significantly more maintainable.
Troubleshooting: Why Mapped Drives Stay After Deletion
Ghost Icons in File Explorer
This is the most common complaint in IT support forums: "I ran net use /delete, but the drive is still showing up in File Explorer."
When this happens, it’s usually due to a desynchronization between the network service and the user interface (UI). File Explorer caches the state of network resources for performance. When you delete a connection via command line, the explorer.exe process doesn't always immediately refresh its cache.
In my experience, about 80% of these "ghost" issues are resolved by simply restarting the Explorer process. You can do this without rebooting the machine:
- Open Task Manager.
- Find "Windows Explorer".
- Right-click and select Restart.
If that doesn’t work, check for active file handles. Sometimes, an application (like an antivirus scanner or a backup agent) is holding a handle to the share, preventing the actual disconnection even if the command reports success. You may need to use Process Monitor to see which process is locking the resources before you can fully sever the link.
Persistent Mappings and Registry Cleanup
If the drive returns automatically after you log off and back on, you are dealing with a persistent mapping. When you create a mapped drive, Windows by default marks it as persistent. This means it writes the connection details to the registry so they survive reboots.
To remove a persistent mapping completely, you must clear the registry entry. The relevant key is located in HKEY_CURRENT_USER\Network. Each drive letter you see there (e.g., Z) has a RemotePath value.
Note: Do not manually delete registry keys unless you are comfortable with the risks. The command-line method below is safer.
You can change the persistence behavior by including the /persistent:no flag in your net use command when you initially disconnect or create drives. But for cleanup, the most reliable method is using the net use command with the /delete flag, which handles the registry cleanup for you. If a drive is "stuck" in the registry but not showing in net use list, it might be orphaned. In rare cases, you may need to manually verify the HKCU\Network key to ensure no stale entries remain.
For domain-joined computers, check your Group Policy. An admin might have a policy set to "Reconnect at user logon" for all mapped drives. If that policy is active, disconnecting locally will be overridden by the server-side policy upon the next logon. You cannot "win" this fight locally; you must ask your domain administrator to modify the GPO.
Preventing Auto-Reconnect and Managing Persistent Drives
Configuring Persistence Settings
If your goal is to create a temporary connection—for example, to copy files from a USB share or a temporary server setup—you should prevent it from becoming permanent.
When connecting a drive, use the /persistent:no flag:
net use T: \\TempServer\Share /persistent:no
This tells Windows: "Connect to this, but do not save it in the registry. When I log out or reboot, this link should disappear."
The default behavior is the opposite: /persistent:yes. This is convenient for regular work drives (like your HR or Finance shared folders), as you don’t want to re-map them every morning. But for ad-hoc tasks, toggling this flag prevents your "This PC" view from becoming a graveyard of dead links.
I’ve found that keeping a strict rule of "persistent for production, non-persistent for testing" saves hours of cleanup time every quarter. It stops the accumulation of disconnected drives that you can’t easily see because they’re hidden in the network view until you specifically look for them.
FAQ
What is the net use command to disconnect a mapped drive?
The direct syntax is net use [DriveLetter]: /delete. For example, to disconnect drive X, you would type net use X: /delete.
Why is my disconnected mapped drive still showing up?
File Explorer often caches disconnected drives. The command-line deletion succeeded, but the UI hasn't refreshed. Try restarting explorer.exe via Task Manager or checking if any application is holding a file handle to that share.
Can I disconnect a network drive without restarting the computer?
Yes. net use /delete is a real-time operation. It severs the connection immediately in your current session. A reboot is only required if you are dealing with persistent registry entries that are locked or if a system-level service is caching the connection, which is rare.
Is it safe to force disconnect a mapped drive in use?
Generally, no. Using /force will terminate any open file handles. If a user has an unsaved document open on that drive, data loss is highly likely. Always close applications and save work before attempting a force disconnect.
Conclusion
Mastering the net use command gives you surgical control over your network connections. While the Graphical User Interface is fine for casual use, the command line offers the precision needed for troubleshooting and automation.
Remember the key distinction: net use manages the actual SMB sessions, while PowerShell’s Remove-SmbMapping offers a more modern, object-oriented interface with better error handling. For most tasks, the CMD approach is faster and lighter. For complex automation or conditional logic, stick with PowerShell.
And finally, don’t ignore the "ghost" drives. Just because net use says a drive is gone, check File Explorer. That final verification step is where you catch the UI desyncs that frustrate so many users.
Next Steps: If you’re looking to automate this further, consider building a scheduled task that runs a cleanup script every night. And if you’ve successfully disconnected your old drives, you’ll need to know how to get them back. Check out our next guide on [Reconnecting Mapped Drives] for the full lifecycle.