You are hereProblem with Drive (un)Mappings
Problem with Drive (un)Mappings
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.
NET USE X: \\SERVER\SHARE
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.
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: http://twitter.com/mojocode