Break on
;Get all currently mapped network drives.
$networkdrives = EnumNetworkDrives()
;Create an array that will hold the letters of all mapped drives.
Dim $mapped[26]
If InGroup("Domain Users")
;Set drive letter.
$drive = "O:"
;Set path.
$path = "\\server\share"
;Check to see if the drive exists.
If Exist($drive + "\")
;Drive exists.
;Check to see if drive settings are correct.
For $i = 0 to UBound($networkdrives)
;Split the current network drives so you get two elements.
;One element holds the drive letter the other holds the path.
$networkdrive = Split($networkdrives[$i], ",")
$networkdriveletter = $networkdrive[0]
$networkdrivepath = $networkdrive[1]
;Check to see if the drive to map matches an existing drive.
If $networkdriveletter = $drive
;Check to see if the path to the drive is correct and if the drive has not
;been mapped by this script already.
If $networkdrivepath = $path And AScan($mapped, $drive) = -1
;Path to the drive is correct.
;Set the display name of the drive.
Label($drive, "User friendly name goes here")
;Set a variable to indicate that this drive has been mapped succesfully.
$mapped[$mappedindex] = $drive
;Increase the index by 1.
$mappedindex = $mappedindex + 1
Else
;Path to the current drive is not correct.
;Delete the drive that uses the drive letter to be mapped.
Use $drive /delete /persistent
;Map correct drive.
Use $drive $path
;Set the display name of the drive.
Label($drive, "User friendly name goes here")
;Set a variable to indicate that this drive has been mapped succesfully.
$mapped[$mappedindex] = $drive
;Increase the index by 1.
$mappedindex = $mappedindex + 1
EndIf
EndIf
Next
Else
;Drive does not exist.
;Map the correct drive.
Use $drive $path
;Set the display name of the drive.
Label($drive, "User friendly name goes here")
;Set a variable to indicate that this drive has been mapped successful.
$mapped[$mappedindex] = $drive
;Increase the index by 1.
$mappedindex = $mappedindex + 1
EndIf
EndIf
;Remove empty elements from the array that holds all mapped drives.
$mapped=removenullrows($mapped)
;Check all old network drives and compare them with the drives that are mapped by this script.
For $i = 0 to UBound($networkdrives)
;Split each drive on the comma.
$networkdrive = Split($networkdrives[$i],",")
$networkdriveletter = $networkdrive[0]
;Check to see if the old rive is listed in the array of newly mapped drives.
If AScan($mapped, $networkdriveletter) = -1
;Old drive is not listed so delete it.
Use $networkdriveletter /Del /Persistent
EndIf
Next