Windows 7
When moving from office A to office B, I have a script that deletes (net use x: /d) the drive mappings from office A, but the drive links remain prominently visible in Windows Explorer / My Computer. They are prominently displayed under Network Location.
The disconnected links have a big red X through them and right-clicking on them and choosing Disconnect results in an error message saying that that drive mapping no longer exists.
How can I force Windows to remove them once they've been disconnected?
Without rebooting? (Scriptable)
7 Answers
There is an easy way to do this: restart Windows Explorer (without shutting down). You could do this with a batch file, like the following:
@echo off
net use * /delete /noconfirm
taskkill /f /IM explorer.exe
explorer.exe
net use x: \\myServer\mySHaredFolder 4 (Windows 8.1 Tested) restart Windows Explorer by killing and restarting the process in the Task Manager. Right-click Windows Explorer -> Restart. Done.
1First, you need have a "Shared Folder" on your hard drive. If you haven't got one already, create a new folder on your hard drive called "Shared", then right-click it and select properties. Click the Sharing tab and tick the "Share this folder" box.
Next, click "My Computer" and in the Tools Menu, click "Map Network Drive".
Notice the little down-arrow next to the drive letter shown. Click the arrow to get a list of letters. Select the one you want to delete, then browse for your Shared folder and select it.
By this means, you will assign the drive letter to a real folder. Make sure the "reconnect at login" box is un-ticked.
Click the Finish button to get a warning. Answer "Yes" and the Shared folder will open. Close it.
Next, right-click the drive in My Computer and select disconnect. Ah, I hear you say, but it is still there! Reboot and it should now be gone.
3I had the same issue; one quick version that works (Windows 7 - 10 at least):
- Open command prompt as admin
Type:
net use /persistent:no- Hit Enter
- Then open Task Manager (on details for Windows 8+) right click explorer and kill it, then go to file, run, and type explorer (hit Enter) to restart it.
Your dead network drives should vanish under My/This computer.
1You can restart Windows Explorer using Task Manager. Kill the explorer process, then go to menu File → New Task (run) and type explorer. Disconnected drives should be gone! (tested on Windows 7).
1I had a problem like this recently, where I had 8 drive letters that didn't show up anywhere, but I couldn't map any new drives of any kind to these letters. What it turned out to be was that they were mapped to "CD-ROM" drives. I have no idea how this happened, but I had eight CD-ROM drives that didn't actually exist. And they were using drive letters that until this problem I had "persistently" mapped to network devices. :Net use [drive]: /delete" had no effect at all.
The only way I got them to release was to go into the Partition Manager control panel and individually disconnect the drive letters from the CD-ROM drives. So far the blocking drives themselves are still in the list in Disk Manager, but hopefully they will go away with another reboot.
For those who have SQL Server Management Studio on your PC, just run this query:
Exec master.dbo.xp_cmdshell 'net use x: /delete'** Change the 'x' according to the drive name...
1