Discussion:
Drive missing from EnumNetworkDrives collection
(too old to reply)
Andy Roxburgh
2007-11-01 13:35:29 UTC
Permalink
Hi, I've got a strange problem.

I'm writing a logon script to map network drives. It checks to see if the
letter is already in use, and if it is it removes the existing mapping and
replaces it with a new one. Very simple. In theory.

The problem I've got is that I can see and explore a mapped network drive in
my Explorer window (in this case 'O:'), which is manually mapped by me to
another location - but it doesn't appear at all the collection returned by
the EnumNetworkDrives method, and then when the script attempts to map it we
get the error "The local device name has remembered a connection to another
network resource".

Anyone know why this is? And is there a way to disconnect the network drive
even though I can't see it in the collection?

Any help appreciated

Andy

P.S. The code is:

Dim strDriveLetter1, strRemotePath1
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
Dim strDebugOutput

strDriveLetter1 = "O:"
strRemotePath1 = "\\WOODSTOCK\Documents"

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()

AlreadyConnected = False

For intDrive = 0 To CheckDrive.Count -1
strDebugOutput = strDebugOutput& " | " & CheckDrive.Item(intDrive)
Next
' show the drives collection
objShell.Popup strDebugOutput

For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter1 Then AlreadyConnected =True
Next
If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter1
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
Else
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
End if
Set CheckDrive = nothing
Andy Roxburgh
2007-11-01 15:52:16 UTC
Permalink
Actually, further to that it seems to only do it when there is a
disconnected network drive visible in Explorer.
The drive letter cannot be removed as a drive, nor can it be assigned.
Post by Andy Roxburgh
Hi, I've got a strange problem.
I'm writing a logon script to map network drives. It checks to see if the
letter is already in use, and if it is it removes the existing mapping and
replaces it with a new one. Very simple. In theory.
The problem I've got is that I can see and explore a mapped network drive
in my Explorer window (in this case 'O:'), which is manually mapped by me
to another location - but it doesn't appear at all the collection returned
by the EnumNetworkDrives method, and then when the script attempts to map
it we get the error "The local device name has remembered a connection to
another network resource".
Anyone know why this is? And is there a way to disconnect the network
drive even though I can't see it in the collection?
Any help appreciated
Andy
Dim strDriveLetter1, strRemotePath1
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
Dim strDebugOutput
strDriveLetter1 = "O:"
strRemotePath1 = "\\WOODSTOCK\Documents"
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count -1
strDebugOutput = strDebugOutput& " | " & CheckDrive.Item(intDrive)
Next
' show the drives collection
objShell.Popup strDebugOutput
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter1 Then AlreadyConnected =True
Next
If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter1
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
Else
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
End if
Set CheckDrive = nothing
Andy Roxburgh
2007-11-02 12:18:44 UTC
Permalink
In case anyone's interested, the answer to this was that the drive in
question was actually marked as 'Unavailable', and apparently VBScript
doesn't let you remove those drives (no idea why, very annoying) so you have
to do it via the shell. so I used

Set objShell = CreateObject("WScript.Shell")
WshShell.Run("net use " & strDriveLetter1 & " /delete /yes"),0

to remove every drive I was about to add, and then I used VBS to add them:

objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1

Works great (although you have to put in a small delay to wait for all the
drives to delete).

Cheers

Andy
Post by Andy Roxburgh
Actually, further to that it seems to only do it when there is a
disconnected network drive visible in Explorer.
The drive letter cannot be removed as a drive, nor can it be assigned.
Post by Andy Roxburgh
Hi, I've got a strange problem.
I'm writing a logon script to map network drives. It checks to see if the
letter is already in use, and if it is it removes the existing mapping
and replaces it with a new one. Very simple. In theory.
The problem I've got is that I can see and explore a mapped network drive
in my Explorer window (in this case 'O:'), which is manually mapped by me
to another location - but it doesn't appear at all the collection
returned by the EnumNetworkDrives method, and then when the script
attempts to map it we get the error "The local device name has remembered
a connection to another network resource".
Anyone know why this is? And is there a way to disconnect the network
drive even though I can't see it in the collection?
Any help appreciated
Andy
Dim strDriveLetter1, strRemotePath1
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive
Dim strDebugOutput
strDriveLetter1 = "O:"
strRemotePath1 = "\\WOODSTOCK\Documents"
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count -1
strDebugOutput = strDebugOutput& " | " & CheckDrive.Item(intDrive)
Next
' show the drives collection
objShell.Popup strDebugOutput
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) =strDriveLetter1 Then AlreadyConnected =True
Next
If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive strDriveLetter1
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
Else
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
End if
Set CheckDrive = nothing
Loading...