PRB: EnumNetworkDrive Will Not Return Remembered Drives (303209)
The information in this article applies to:
- Microsoft Windows Script Host 1.0
- Microsoft Windows Script Host 2.0
This article was previously published under Q303209 SYMPTOMS
The EnumNetworkDrive method from Windows Script Host (WSH) only returns connected drives. This can be a problem if a remembered drive exists and EnumNetworkDrives is being used to determine the next available drive letter. If an attempt is made to map to that same drive letter as a remembered drive, an error message is returned:
800704B2 An attempt was made to remember a drive that had previously been remembered.
CAUSE
This is caused by a limitation of the EnumNetworkDrives method. This method only scans for a connection with a status of "CONNECTED".
RESOLUTION
The following are two ways to work around this problem:
'Method 1
On Error Resume Next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Do
err.Clear
AvailableLetter = GetNextLetter(AvailableLetter)
WScript.Echo AvailableLetter
WshNetwork.MapNetworkDrive AvailableLetter, "\\Server\Share"
Loop Until err.Number = 0 'This could possibly not return so you may
'want to say "Loop Until err.Number <> xxxxxxx
'where xxxxxxx is the err number you receive.
Set WshNetwork = Nothing
Function GetNextLetter(DriveLetter)
'Start x at the ascii value of the drive letter to start the search
'unless something is passed in. This sample uses capital letters and
'starts at F.
If IsEmpty(DriveLetter) Then
x = 70
Else
x = Asc(drive)
End If
Set oDrives = WshNetwork.EnumNetworkDrives
'Step by two since the first item in the collection is the drive letter
'and the second item is the network mapping
For i = 0 to oDrives.Count - 1 Step 2
If chr(x) & ":" = oDrives.Item(i) Then
x = x + 1
End If
Next
GetNextletter = chr(x) & ":"
End Function
'Method 2
'This will list all mapped connections
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%comspec% /c net use > somefile.txt"
'This will map to the next available drive letter
WshShell.Run "%comspec% /c net use * \\servername\sharename"
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 3/20/2004 |
---|
Keywords: | kbDSWManage2003Swept kbprb KB303209 |
---|
|