J
[JackJack]
Guest
Initial situation (tested with Windows 10, 8.1, 7 and XP):
At this point I'd like to remove that network drive using my software.
There are multiple ways to do this.
- Probably the easiest way to reproduce it is by command line: net use X: /delete
- API: WNetCancelConnection2 or WNetDisconnectDialog1
- Disconnect dialog: Explorer main menu > Tools > Disconnect network drive (7/XP) or the submenu "Disconnect network drive" (10/8.1) while no drive is selected when the click is performed
and a couple of others.
All of them result in the problem that the drive letter icon remains in the Explorer although the network drive has been disconnected.
Some details that indicate that this is a bug and not feature:
- Although the drive letter icon is shown in the Explorer it's not visible in any other software and not accessible through Windows API
- The drive letter can be used for a new network drive connection. If done so, the new path is mapped to it, but the old name/path remains in the Explorer.
- The drive letter can be used to be assigned to a local drive in the Disk Management dialog. For example after changing the drive letter of a DVD drive to the disconnected network drive letter the drive is still shown as a network drive in the Explorer but leads to the content of the DVD drive.
To solve this problem at this point the user has either to log off and on again or kill explorer.exe and run it again. This shows that it's some kind of orphaned drive in some internal Explorer cache or object list that is not removed correctly.
There is one way to remove the drive correctly in the first place:
Right-click on the drive and choose "Disconnect". This works flawlessly! The network drive is disconnected and immediately removed. Notice: this only works if done in the first place. If the drive has already been disconnected using one of the other methods, this option will only show "This network connection does not exist."
I've discussed this problem with many experts already and there doesn't seem to be a workaround for this. At the moment if you want to programmatically disconnect a persistent network drive that wasn't available during logon you'll end up with an orphaned drive.
This applies to all Windows versions from XP to 10, x64 and x86. (older versions not tested)
Is there any chance this could be solved by patching Windows?
More...
- Create a persistent (!) network drive mapping (a.k.a. "Reconnect at logon") using the integrated/official "Map Network Drive" dialog .
- Now physically disconnect from the network folder (unplug the cable or shut down the target system)
- Log off and on again. A balloon message will tell "Could not reconnect all network drives", but the drive will still be visible in the Explorer (with a red cross). The balloon message is the best indication that you've reproduced the steps correctly.
At this point I'd like to remove that network drive using my software.
There are multiple ways to do this.
- Probably the easiest way to reproduce it is by command line: net use X: /delete
- API: WNetCancelConnection2 or WNetDisconnectDialog1
- Disconnect dialog: Explorer main menu > Tools > Disconnect network drive (7/XP) or the submenu "Disconnect network drive" (10/8.1) while no drive is selected when the click is performed
and a couple of others.
All of them result in the problem that the drive letter icon remains in the Explorer although the network drive has been disconnected.
Some details that indicate that this is a bug and not feature:
- Although the drive letter icon is shown in the Explorer it's not visible in any other software and not accessible through Windows API
- The drive letter can be used for a new network drive connection. If done so, the new path is mapped to it, but the old name/path remains in the Explorer.
- The drive letter can be used to be assigned to a local drive in the Disk Management dialog. For example after changing the drive letter of a DVD drive to the disconnected network drive letter the drive is still shown as a network drive in the Explorer but leads to the content of the DVD drive.
To solve this problem at this point the user has either to log off and on again or kill explorer.exe and run it again. This shows that it's some kind of orphaned drive in some internal Explorer cache or object list that is not removed correctly.
There is one way to remove the drive correctly in the first place:
Right-click on the drive and choose "Disconnect". This works flawlessly! The network drive is disconnected and immediately removed. Notice: this only works if done in the first place. If the drive has already been disconnected using one of the other methods, this option will only show "This network connection does not exist."
I've discussed this problem with many experts already and there doesn't seem to be a workaround for this. At the moment if you want to programmatically disconnect a persistent network drive that wasn't available during logon you'll end up with an orphaned drive.
This applies to all Windows versions from XP to 10, x64 and x86. (older versions not tested)
Is there any chance this could be solved by patching Windows?
More...