You are hereProblem with Drive (un)Mappings

Problem with Drive (un)Mappings

By steve - Posted on 20 August 2007

I have a client that uses a logon script on a Windows 2003 Small Business Server. The first thing the script does is un-map any mapped drives that might get used.

Most of the time the script works fine, but once in awhile, a certain user on a certain computer would lose all of the drive mappings and none of the drives would work. They might reboot a few times before things worked again.

After some work, we figured out that the script was hanging on the last NET USE /delete command and giving the error 2250 "There are open files and/or incomplete directory searches pending on the connection to X:" (where X: was the drive with the issue)...

The script would then hang for awhile with a prompt of "Is it OK to continue disconnecting and force them closed? (Y/N) [N]:". The script hung until it gave up or was cancelled by the user.

I googled and tried a few things, but couldn't get the problem to repeat often enough to come up with the error consistently.

Finally, I figured out that I could simply map a drive, then open a CMD window and switch to that drive in the same window and I would get the message consistently. That made it easier to debug.

Click Start/Run

Once I was able to easily get the error, I played around with it and found that if I, obviously, could just answer Y to the prompt, things would finish up OK and the script would continue.

However, I didn't want the user to have to keep answering "yes, it is OK to do something we obviously want to do".

Now with most prompts from Windows commands, you can either pass an option to a command or fake it out to get it to automatically respond to any prompts that might come along. For instance, you can create a file with just the letter Y in it and do something like this:

NET USE Z: /delete <y.txt

Or you can use a pipe to push a response into a command:

echo Y|NET USE Z: /delete

But neither of these worked. When I tried it, I would get "No valid response was provided" as a response.

There weren't any documented auto-response values either.

Just by chance and in desperation, I tried this:

NET USE Z: /delete /y

And it worked! (Notice the /y at the end?) Apparently there is an undocumented command option of /y to respond YES to any prompts. I looked again after figuring this out and there isn't any reference to /y in the command help or Microsoft's website.

The screen still displays the warnings:

There are open files and/or incomplete directory searches pending on the connection to z:.

z: was deleted successfully.

But the delete does get done. You can get rid of those messages by sending output to NUL:

NET USE Z: /delete /y >NUL

Now you'll have a nice quite response to the attempt to unmap the drive.

Just a warning: if you really do have files open on that mapped drive when unmapping, you could corrupt the data files by forcing the unmap. While the example above is really just a way of doing what the user was probably going to do anyway, all the cautions and warnings apply.


Thank you for this

Nice to know about that /y parameter, will come in handy, presuming it works on other commands.

Still no closer to finding out what files it could be though :(

You can try looking in the server's open file list:

Click Start/Run
System Tools/Shared Folders/Open Files

That should show you any open files. If the problem is with pending directory searches, they won't be listed there.

I frequently get in a situation where an attempt to delete or rename a file results in a message box claiming that

"Cannot delete so-and-so: It is being used by another person or program. Close any programs that might be using the file and try again."

OK: I'm not using it. Neither am I running any programs that are currently using it. But I may have cancelled programs in mid-stream during testing before the file in question was closed.

Any ideas on how I can close this file or otherwise free it up? In the past, I would just reboot Windows, but this is on a server, and rebooting is not an option.

Thanks in advance!

If you have GUI access to the server and you are running Windows 2000 Server or higher, you can cancel open files by doing this:

* Right click the "My Computer" icon
* Click on "Manage"
* Open "System Tools" in the tree
* Open "Shared Folders"
* Open "Open Files"
* You should see the problem file in the list and who has it open.
* Right click on the file
* Take the option to "Close Open File"

XP and 2003 have a command line utility called "openfiles.exe" that shows you that same list of files. You can also use that command to "/disconnect" open files.


There is a program I found to help with the vague "It is being used by another person or program" message called Unlocker. It adds an entry to the context menu which allows you to view which processes are locking the file and the option to remove the lock or kill the process.

We find the most common culprit for this is either cidaemon.exe (i.e. the indexing service) or antivirus.

If it's the indexing service, restarting the indexing service will free up the file.

This is definitely a very good input man. /y parameter actually helps.

Great job mate!
Thanks a lot.

Even over 7 years later this is extremely helpful - Thanks!

Helped me too.

Did this help you? You can help me!

Did you find this information helpful? You can help me back by linking to this page, purchasing from my sponsors, or posting a comment!

+One me on Google:

Follow me on twitter:


Affiliation Badges