Andy Roxburgh
2007-11-01 13:35:29 UTC
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
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