On a similar issue, I have been trying to develop a function that will only map a drive if it's not already mapped, but will also accept an option "force-map" flag to remap if required. The domain is NT4 and all clients are either W2K or XP. The problem is that if the "force-map" is set and the drive is already mapped. The /DELETE option leaves the drive in a strange state. NET USE at the command windows shows "Unavailable" or "Disconnected" but that prevents the following USE from working.
code:
Function MapDrive($letter, $unc, Optional $force)
Dim $fso, $drivemap, $sharename
$fso = CreateObject("Scripting.FileSystemObject")
If $fso
$drivemap = $fso.GetDrive("$letter")
If $drivemap
$sharename = $drivemap.ShareName
? "...Already mapped: "+$letter+" to "+$sharename
If $force = 1
? "...Forced mapping: "+$letter+" to "+$unc
USE "$letter" /DELETE
Sleep 1
USE "$letter" "$unc" /PERSISTENT
$drivemap = $fso.GetDrive("$letter")
If $drivemap
$MapDrive = 1
Else
$MapDrive = 0
EndIf
Else
$drivemap = $fso.GetDrive("$letter")
? "...Already mapped: "+$letter+" to "+$drivemap.ShareName
$MapDrive = 1
EndIf
Else
? "...Mapping drive: "+$letter+" to "+$unc
USE "$letter" "$unc" /PERSISTENT
Sleep 0.5
$drivemap = $fso.GetDrive("$letter")
If $drivemap
$MapDrive = 1
Else
$MapDrive = 0
EndIf
EndIf
EndIf
$drivemap = 0
$fso = 0
EndFunction
$=MapDrive("U:", "\\vbcsr0001\e$\WebSites", 1)
$=MapDrive("V:", "\\vb-svr-04\C$")
$=MapDrive("X:", "\\vabsr0004\c$")
Anything in this code (above) that I've hosed up somewhere? If I'm reinventing the wheel, please point me to a better solution if possible? THanks!
_________________________
silence is golden, but duct tape is silver