HKFuey
asked on
Map Drives vbs causes errors
I have this script to map drives in AD 2003: -
Set objNetwork = CreateObject("WScript.Netw ork")
objNetwork.MapNetworkDrive "K:" , "\\files\shared"
objNetwork.MapNetworkDrive "S:" , "\\files\users"
The users get errors if drive is already mapped does anyone know the syntax to delete then map drives?
Set objNetwork = CreateObject("WScript.Netw
objNetwork.MapNetworkDrive
objNetwork.MapNetworkDrive
The users get errors if drive is already mapped does anyone know the syntax to delete then map drives?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use the EnumNetworkDrives Method of the Wscript.Network object
something like
set objdrive = objNetwork.EnumNetworkDriv
For intDrive = 0 to objDrive.Count -1 Step 2
intNetLetter = IntNetLetter +1
letter=objDrive.Item(intDr
unc=objDrive.Item(intDrive
If letter="K:" and unc <> "\\files\shared" Then
oNet.RemoveNetworkDrive "K:", true, true
End If
If letter="S:" and unc<>"\\files\users\" Then
oNet.RemoveNetworkDrive "S:", true, true
End If
Next
oNet.MapNetworkDrive "K:", "\\files\shared", true
oNet.MapNetworkDrive "S:", "\\files\users", true
ASKER
I did try that but I get errors if the drive is not mapped already!