How to unmap "ghost" network drive

I

Ilya Evseev

Hi!
There is a script calling by System Agent that maps external network share to drive letter.
When this script fails without unmapping network drive,
I don't have any possibility to release drive letter.
Only rebooting has effect, but this is absolutely impossible on server box.

Scheduled script performs safe checking as following:
-----------------------------
if not exist z:\nul goto mapdrive
net use z: /delete /yes
if not exist z:\nul goto mapdrive
echo Error: cannot unmap Z: drive, abort.
goto done
:mapdrive
net use z: \\server\share
...
:done
-----------------------------
All output is redirected to file using >>logfile.txt 2>&1
and contain "Error: cannot unmap" lines preceding by error output of "net use z: /delete":
-----------------------------
The network connection could not be found.
More help is available by typing NET HELPMSG 2250.
-----------------------------

Drive Z: is not visible in "My Computer" nor in "net use" output.
However, "Start->Programs->Administrative Tools->Computer Management->Logical drives"
contains record of network drive Z: with "Information not available" hint,
but this record cannot be deleted anyway.

Script is running under Administrator account, but HKCU\Network does not contain "Z" subkey.

So, my question is very simple: how to unmap this drive???
My Windows is 2000 Server SP4 with Terminal Services.

Long live Linux,
Ilya
 
P

Pegasus \(MVP\)

Ilya Evseev said:
Hi!
There is a script calling by System Agent that maps external network share to drive letter.
When this script fails without unmapping network drive,
I don't have any possibility to release drive letter.
Only rebooting has effect, but this is absolutely impossible on server box.

Scheduled script performs safe checking as following:
-----------------------------
if not exist z:\nul goto mapdrive
net use z: /delete /yes
if not exist z:\nul goto mapdrive
echo Error: cannot unmap Z: drive, abort.
goto done
:mapdrive
net use z: \\server\share
...
:done
-----------------------------
All output is redirected to file using >>logfile.txt 2>&1
and contain "Error: cannot unmap" lines preceding by error output of "net use z: /delete":
-----------------------------
The network connection could not be found.
More help is available by typing NET HELPMSG 2250.
-----------------------------

Drive Z: is not visible in "My Computer" nor in "net use" output.
However, "Start->Programs->Administrative Tools->Computer Management->Logical drives"
contains record of network drive Z: with "Information not available" hint,
but this record cannot be deleted anyway.

Script is running under Administrator account, but HKCU\Network does not contain "Z" subkey.

So, my question is very simple: how to unmap this drive???
My Windows is 2000 Server SP4 with Terminal Services.

Long live Linux,
Ilya

Your share is probably mapped to a drive letter by a background
process, e.g. by a scheduled task or by a spawned command
processor. You must ensure that all such tasks unmap all
mapped drives before they terminate.
 
I

Ilya Evseev

Pegasus said:
Your share is probably mapped to a drive letter by a background
process, e.g. by a scheduled task or by a spawned command
processor. You must ensure that all such tasks unmap all
mapped drives before they terminate.

I understand and agree your idea, but my question was in another:
what to do when background task is terminated abnormally and drive still mapped?
How to unmap it from outer environment without rebooting?

Ilya
 
P

Pegasus \(MVP\)

Ilya Evseev said:
I understand and agree your idea, but my question was in another:
what to do when background task is terminated abnormally and drive still mapped?
How to unmap it from outer environment without rebooting?

Ilya

This little experiment might give you a pointer. Here is what I typed on my
machine:

1. runas /user:config cmd
2. net use p: \\fnlhome\c$
3. exit
4. net use
C:\Temp\Radio>net use
New connections will not be remembered.
Status Local Remote Network
--------------------------------------------------------------------------
Disconnected \\ipex2000\d$ Microsoft Windows Network
The command completed successfully.

As you see, drive P: does not show.

5. runas /user:config cmd
6. net use
New connections will be remembered.
Status Local Remote Network
----------------------------------------------------------------------------
---
Unavailable P: \\fnlhome\c$ Microsoft Windows Network

Now drive P: is visible but unavailable
7. net use P: /del
P: was deleted successfully.
8. exit

In other words: I spawned a command processor under the same
credentials as the original command processor. I was then able to
delete the mapped drive. However, this will NOT work if you have
any open handles on that drive.
 
I

Ilya Evseev

Pegasus said:
In other words: I spawned a command processor under the same
credentials as the original command processor. I was then able to
delete the mapped drive. However, this will NOT work if you have
any open handles on that drive.

In your example, Z: is created using ordinal user account.
My script is called under Administrator credentials. Try so:

net use ...does not contain Z:
runas /user:dom\administrator cmd
net use z: \\serv\mydata
net use ...contains Z:!
exit
net use ...does not contain Z:
net use z: \\serv\mydata ...displays error: Device is already in use
runas /user:dom\administrator cmd
net use ...does not contain Z:
net use z: \\serv\mydata ...displays error: Device is already in use

WBR, Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top