• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1490
  • Last Modified:

Unable to disconnect network drive windows

I have mapped a network drive using the WScript object through an ASP page. See below:

Set WshNetwork= CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives

WshNetwork.MapNetworkDrive driveletter,"remoteserver", False, "username", "password"

' do some work
WshNetwork.RemoveNetworkDrive (driveletter)
Set WshNetwork= Nothing

This all seems to work fine except sometimes the drive doesn't get removed and when i log into the server to try and disconnect the drive, it tells me the network connection cannot be found. The network drive is displayed with a red 'X' over it. If I try to remap it, it does not appear in the list of drives. If i use the net use delete command it doesn't work either. The only solution I have found to this problem is rebooting the server and there's only a certain number of times a day i like to do that. Any suggestions would be great as I've been trying to solve this problem for a while now.
1 Solution
Check the following registry keys for the Dword values below.  I doubt whether this is the problem though, since it is primarily for only removing the context menu option, but you may want to ck anyway...

User Key: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\
System Key: [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\
Value Name: NoNetConnectDisconnect
Data Type: REG_DWORD (DWORD Value)
Value Data: (0 = disabled, 1 = enabled)
SplinstAuthor Commented:
that didn't seem to show up anything but thanks anyway. Any other ideas?
Next time it happens to you, search the registry for the mapped drive and delete the realted key.
See if it fixes your problem without booting the server.
Commonly when one disconnects a network drive, one should flush out all the remaining data the the cashe memory.  When open a file and does some change to it and close, windows might not actually update it until when it's free.  Calling disconnecting routine without calling cleaning up routines, might result in disconnecting the network incomplete.  I don't know .NET programming, but that is the general rules.

Hope that help.
I had same problem.
Here workaround:
in this example x: drive
-cmd delete net network drive: net use x: /d
- regedit remove following folder 'x' under reg-key [HKCU]\Network
Reboot system.
hope this helps

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now