Win2000 File Share Mapping bug 
Author Message
 Win2000 File Share Mapping bug

All,

I've uncovered a Windows 2000 bug that I can't seem to find a workaround for.  If you map a drive letter to a network share in a process without a desktop (such as a scheduled task or a service), the mapping gets corrupted when the process shuts down so that attempting to remap the drive again fails.  To demonstrate do the following:

1. Paste the following code into a file called c:\maptest.vbs and set the sDrive and sUC constants:

Const sDrive = "Q:" ' or any unused local drive

Const sUNC   = \\MyServer\MyShare ' change this to a valid share on your network

Dim WshShell
Dim WshNetwork
Dim sDrive
Dim sUNC

On Error Resume Next

Set WshShell=WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")

'  Attempt to delete the Q: drive mapping

WshNetwork.RemoveNetworkDrive sDrive, True, True
WshShell.Logevent 4, "RemoveNetworkDrive Error: " & Err.Description

Err.Clear

' Attempt to map the Q: drive
WshNetwork.MapNetworkDrive sDrive, sUNC, False
WshShell.Logevent 4, "MapNetworkDrive Error: " & Err.Description

' WshShell.Logevent 4, "RemoveNetworkDrive Error: " & Err.Description

2. Open the Scheduled Tasks viewer (Start-->Settings-->Control Panel-->Scheduled Tasks)

3. Click "Create Scheduled Task"

4. Create a task to run c:\maptest.vbs. Set it to run "When my computer starts" (you will not need to reboot for this test)

5. Set the task to run as a user who has access to the share.

6. In the scheduled tasks viewer, right click on the task you just created and choose "Run".  Repeat this step to run the task a second time.

7. Open the Event Viewer (Start-->Adminstrative Tools-->Event Viewer) and click on Application.  Look for the 4 events toward the top with a source of "WSH". Here are the events you should see in chronological order (events shown in red):

  a.. RemoveNetworkDrive Error: This network connection does not exist. (no drive existed to delete so this error is correct)
  b.. MapNetworkDrive Error:   (created the drive mapping without error)
  c.. RemoveNetworkDrive Error: This network connection does not exist. (aha, it can't remove the drive mapping we just created)
  d.. MapNetworkDrive Error: The local device name is already in use. (even worse, we can't recreate it either)

Here's what little I do know about this problem:

  a.. Rebooting resolves the problem until the app is again run more than once (not a viable solution in a production server environment).
  b.. Using "NET USE" or calling network API's in a VB app to do the mapping/unmapping gives the same results.
  c.. It is similar to the problem in article Q253821 but the problem is not limited to non-administrative accounts only and changing the registry key does not resolve the problem.
  d.. The symptoms are similar to those described in article KB130668.
  e.. I have also tried this mapping scenario in a VB app started by the SrvAny service with the same results.
  f.. Uncommenting the last line in the script above fixes the problem.  Do to the nature of my app (a VB app started by SrvAny), I cannot always be certain that unmapping takes place.

Is there some magic registry value that I can set or some API call I can make prior to mapping that will resolve this?

Thanks in advance,

Steve Waldner



Sat, 30 Apr 2005 11:59:41 GMT  
 Win2000 File Share Mapping bug

Quote:
>   c.. RemoveNetworkDrive Error: This network connection does not
> exist. (aha, it can't remove the drive mapping we just created)

This is a known problem fixed in WSH 5.6.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Sat, 30 Apr 2005 23:02:32 GMT  
 Win2000 File Share Mapping bug
Installing WSH 5.6 does not resolve this problem..I tried it.  It is a bug
in Windows 2000, not in WSH.

Thanks,

Steve Waldner



Quote:
> >   c.. RemoveNetworkDrive Error: This network connection does not
> > exist. (aha, it can't remove the drive mapping we just created)

> This is a known problem fixed in WSH 5.6.

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US



Sun, 01 May 2005 01:08:13 GMT  
 Win2000 File Share Mapping bug

Quote:

> Installing WSH 5.6 does not resolve this problem..I tried it.  It is
> a bug in Windows 2000, not in WSH.

Actually my reply was in error...

The problem fixed by WSH 5.6 involved RemovePrinterConnection, not
RemoveNetworkDrive.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Sun, 01 May 2005 01:54:06 GMT  
 Win2000 File Share Mapping bug
How about not specifying a drive letter - and just using unc paths
\\hostmachine\c$ instead?
Then reference the unc path from your program...

Jake



Quote:

> > Installing WSH 5.6 does not resolve this problem..I tried it.  It is
> > a bug in Windows 2000, not in WSH.

> Actually my reply was in error...

> The problem fixed by WSH 5.6 involved RemovePrinterConnection, not
> RemoveNetworkDrive.

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US



Sun, 01 May 2005 06:25:43 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Win2000 File Share Mapping bug

2. Shared Memory via Memory-Mapped Files

3. Map many network shares using text file

4. Directory, share, Win2000, access rights, ADSI

5. Directories, sharing, Win2000, Access rights, ADSI

6. Share Permissions in Win2000

7. OutputDebugString Bug in Win2000

8. ComboBox bug in Win2000??

9. GetPrivateProfileString - bug under Win2000

10. Map and disconnect NT shares via code?

11. Map/UnMap Network Share Connections --> VB.Net

12. Mapping Network Share Help

 

 
Powered by phpBB® Forum Software