Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Howdy, I'm having some trouble with getting my logon script to disconnect M: from it's current mapping and then reconnect M: drive to it's new destination. My logon script is as follows;
Set WshShell = WScript.CreateObject("WScript.Shell")
' set the variables.Set CofNet = WScript.CreateObject("WScript.Network")
Set CheckDrive = CofNet.EnumNetworkDrives()DriveLetter = "M:"
RemotePath = "\\10.10.10.20\City_Sds"
' For ... Next loop
AlreadyConnected = False
For i = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(i) = DriveLetter Then AlreadyConnected = True
Next' If = then, else
' This section tests to see if the Drive is already mapped, and if yes then to disconnect
If AlreadyConnected = True then
CofNet.RemoveNetworkDrive DriveLetter
CofNet.MapNetworkDrive DriveLetter, RemotePath
WshShell.PopUp "Drive " & DriveLetter & "Disconnected, then connected successfully."Else
CofNet.MapNetworkDrive DriveLetter, RemotePath
WshShell.PopUp "Drive " & DriveLetter & " connected successfully."End if
It works great if there is no drive mapped to M: or if the drive mapped to M: was connected via logon script. However if the M: drive was mapped on the local computer and the reconnect at logon box checked the script will disconnect M: and then give the following error when trying to remap M: to it's new location;
Windows Script Host
An attempt was made to remember a device that had previously been remembered.I've also tried this with the net use /d in a batch file and the same thing happens.
Any ideas? Thanks in advance
Thanks,
Tony
Thanks,
Tony

If either one of those isn't working, my guess is because there is a file or something in use on the existing M drive. Thus you can't disconnect it easily. Maybe poke around Microsoft's website a little to see if this is documented. Also, make sure there isn't a conflict between the time the disconnect command is initiated to when it tries to connect the new path (there is quite a lag when disconnecting some drives).
I'd suggest testing it by mapping a drive as M, then open a file via the network drive and try some network commands to close the connection.
If I were you, I'd have my script first try to disconnect the existing M drive. Then if it didn't successfully diconnect I'd just have a VBS window display telling the user how to manually disconnect that they'd need to log off and back on again in order to have the M drive available.
Not sure if that's an option in your environment or not...

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |