Kris -
Perhaps this code can assist. Longer and more complex than my compatriates on the board as I have not mastered
UDFs, but works. It will load arrays with drive letters and drive shares in use on the workstation for all
LOCAL, PERSISTENT or NETWORK MAPPED drives.
It will compare each network mapping attempt against the arrays to determine if:
+ the drive letter is in use, mapped to another resource
+ the drive letter in use is already mapped to the desired resource
+ another drive is already mapped to that resource

Depending upon error conditions you desire, you can modify the code to skip some mappings, etc.

I have not attempted the printers, but perhaps the logic presented in this code can assist you as most of that info is stored in registry keys.

If of use to you and you've additional questions, email me as it's been some time since I've been on the board. And of course, if no use to you, simply ignore!

Bill

code:
; ########################################################
; ## FILE NAME: CHECKDRIVES.KIX ##
; ## LOCATION : \NETLOGON ##
; ## REVISION : 2003.01.01.1a ##
; ## KiX VER : 4.11 ##
; ## ##
; ## NOTES: Script to check local and persistent ##
; ## drives in use, and map network drives. ##
; ## AUTHOR : Bill Leonard ##
; ########################################################

; -------------------------------------------------------------------------

:CheckLocalDrives

; Determine local drive letters in use on WinXP/2K/9x systems
; -------------------------------------------------------------------------

; ** Declare variables as LOCAL (DIM, script-specific) or GLOBAL (KiX-session)
DIM $LocBreak, $Ok1, $Ok2, $RegKey, $TmpDrv, $TmpKey, $TmpVal, $TmpVal1, $TmpVal2, $TmpVal3
GLOBAL $DrvAll, $DrvEsdi, $DrvLocl, $DrvScsi, $DrvUnkn, $MapErrCnt
$DrvAll = ""
$DrvEsdi = ""
$DrvLocl = ""
$DrvScsi = ""
$DrvUnkn = ""


; ** If WinNT, skip to next section as info stored in registry as unreadable binary
; ** Can not determine local drives foe WinNT (binary in registry), block these letters from usage in other mappings
; ** The WinNT letters are suggested letters, not exact determinations, so some problems can be expected for some users
SELECT
CASE ($OS = "WinNT") $DrvLocl = "ABCDE" GOTO "ChkDrivesEnd"
CASE ($InWin = 1) GOTO "Win2KDrives"
CASE (1) GOTO "Win9XDrives"
ENDSELECT


:Win9XDrives
; ** Checks Win9x registry values
$x=0
DIM $RegKey1[3]
$RegKey1[$x] = "HKEY_LOCAL_MACHINE\Enum\ESDI" $x=$x+1
$RegKey1[$x] = "HKEY_LOCAL_MACHINE\Enum\FLOP" $x=$x+1
$RegKey1[$x] = "HKEY_LOCAL_MACHINE\Enum\SCSI" $x=$x+1
$x2=0
DO
IF KEYEXIST ($RegKey1[$x2]) = 1
$Ok1 = N
$x3 = 0
DO
$TmpVal1 = ENUMKEY ($RegKey1[$x2], $x3)
IF (@ERROR = 0)
IF (LEN ($TmpVal1) <> 0)
$Ok2 = N
$x4 = 0
$TmpKey = $RegKey1[$x2] + "\" + $TmpVal1
DO
$TmpVal2 = ENUMKEY($TmpKey, $x4)
IF (@ERROR = 0)
$TmpKey = $TmpKey + "\" + $TmpVal2
$TmpVal3 = READVALUE ($TmpKey, "Class")
$TmpDrv = READVALUE ($TmpKey, "CurrentDriveLetterAssignment")
IF (LEN ($TmpVal3) <> 0) AND (LEN ($TmpDrv) >= 1)
IF (INSTR ($DrvScsi, $TmpDrv) = 0) AND (INSTR ($DrvEsdi, $TmpDrv) = 0) ; ** Is drive letter already recorded?
SELECT
CASE (LCASE ($TmpVal3) = "cdrom") $DrvScsi = $DrvScsi + $TmpDrv
CASE (LCASE ($TmpVal3) = "diskdrive") $DrvEsdi = $DrvEsdi + $TmpDrv
CASE (1) $DrvUnkn = $DrvUnkn + $TmpDrv
ENDSELECT
ENDIF
ENDIF
ELSE $Ok2=Y
ENDIF
$x4=$x4+1
UNTIL ($Ok2 = Y)
ENDIF
ELSE $Ok1=Y
ENDIF
$x3=$x3+1
UNTIL ($Ok1 = Y)
ENDIF
$x2=$x2+1
UNTIL $x2=$x
GOTO "ChkDrivesEnd"

:Win2KDrives
; ** Checks WinXP/2K registry values. Note, WinXP/2K resgistry entries do not differentiate between ESDI/SCSI
; ** Data is stored in Binary, so no details of the device are obtainable (CD, SCSI, etc.)
$RegKey = "HKEY_LOCAL_MACHINE\SYSTEM\MOUNTEDDEVICES"
IF KEYEXIST ($RegKey) = 1
$LocBreak = "N"
$x=0
WHILE (@ERROR = 0) AND ($LocBreak = "N")
$TmpVal = ENUMVALUE ($RegKey, $x)
IF (@ERROR = 0) AND (LEN ($TmpVal <> 0))
IF INSTR ($TmpVal, "DosDevices")
$TmpDrv = UCASE (SUBSTR ($TmpVal, LEN ($TmpVal)-1,1))
IF (INSTR ($DrvLocl, $TmpDrv) = 0) ; ** Skip duplicate drive letter entries
$DrvLocl = $DrvLocl + $TmpDrv
ENDIF
ENDIF
ELSE
$LocBreak = "Y"
ENDIF
$x=$x+1
LOOP

IF (LEN ($DrvLocl) <> 0) AND INSTR ($DrvLocl, "0") $DrvLocl = SUBSTR ($DrvLocl, 1, LEN ($DrvLocl)-1)
ELSE $DrvLocl = SUBSTR ($DrvLocl, 1, LEN ($DrvLocl))
ENDIF
ENDIF

:ChkDrivesEnd
IF (LEN ($DrvEsdi) <> 0) $DrvEsdi = UCASE ($DrvEsdi) ENDIF
IF (LEN ($DrvScsi) <> 0) $DrvScsi = UCASE ($DrvScsi) ENDIF
IF (LEN ($DrvLocl) = 0) $DrvLocl = $DrvEsdi + $DrvScsi ENDIF
IF (LEN ($DrvUnkn) <> 0)
$Err = $Err+1
$DrvUnkn = UCASE ($DrvUnkn)
$wri = WRITELINE (1, "Check unknown drives recorded: $DrvUnkn" + $CR)
ENDIF

$DrvAll = $DrvLocl
GOSUB "AlphaDriveLetters"
IF ($OS = "WinNT") $Msg = "Skipped verify drive letters in use on WinNT system - blocking out $DrvAll"
ELSE $Msg = "Verified drive letters in use by local ESDI/SCSI devices: $DrvAll"
ENDIF
$wri = WRITELINE (1, "$Msg" + $CR)


; -------------------------------------------------------------------------

:CheckHomeDrive

; Determine if Home drive for user, set appropriate variables
; Perform before Persistent Drives in case users mapping their HomeDrv persistently
; -------------------------------------------------------------------------

; ** Declare variables as LOCAL (DIM, script-specific) or GLOBAL (KiX-session)
DIM $TmpShr
GLOBAL $DrvArrayIdx, $HomeChk, $HomeDrv, $HomeFullShr, $HomeShr, $HomeSvr
GLOBAL $DrvArrayLtr[30] ; ** Array to cross reference mapped drive letters
GLOBAL $DrvArrayShr[30] ; ** Array to cross reference mapped drive shares
$DrvArrayIdx = 0
$HomeChk = N ; ** Bucket tracking successful home drive connection

; ** Set HOME drive variables - drive letter, server name, root share. Undefined HOME dir recorded in logs under drive mapping routine
$RC = @HOMESHR
IF ($RC = "") $HomeDrv = "Undefined"
ELSE
$RC2 = @HOMEDRIVE
IF ($RC2 = "") $HomeDrv = "H:"
ELSE $HomeDrv = @HOMEDRIVE
ENDIF
$TmpShr = SUBSTR (@HOMESHR, 3, LEN (@HOMESHR)) ; ** Parse value '\\server\share' for 'server\share', remove leading '\\' so further parsing for '\' will work
SELECT
CASE (INSTR ($TmpShr, LCASE ("\Home")) <> 0) ; ** Profile Home DIR formatted: \\Server\Home\UserName / \\Server\Home\UserName$
$HomeShr = @LONGHOMEDIR ; ** Set variable to KiX Macro value
IF (SUBSTR (@LONGHOMEDIR, LEN (@LONGHOMEDIR), 1) <> "$") ; ** Check if '$' character at end of value indicating hidden share defined
$HomeShr = @LONGHOMEDIR + "$" ; ** Set variable to KiX Macro value, add '$' as share should be hidden
ENDIF
$XtraDir = SUBSTR ($TmpShr, INSTR ($TmpShr, "\")+1, LEN ($TmpShr)) ; ** Parse value, removing value of extra DIR 'users' to get to Server name
$HomeSvr = UCASE (SUBSTR (@HOMESHR, 1, LEN (@HOMESHR)-LEN ($XtraDir)-1)) ; ** Parse server name from user profile string
CASE (1) ; ** Profile Home DIR formatted: \\Server\UserName / \\Server\UserName$
$HomeShr = SUBSTR ($TmpShr, INSTR ($TmpShr, "\")+1, LEN ($TmpShr))
IF (SUBSTR ($HomeShr, LEN ($HomeShr), 1) <> "$")
$HomeShr = $HomeShr + "$"
ENDIF
$HomeSvr = UCASE (SUBSTR (@HOMESHR, 1, LEN (@HOMESHR)-LEN ($HomeShr)-1))
ENDSELECT
$HomeFullShr = $HomeSvr + "\" + $HomeShr
ENDIF


; -------------------------------------------------------------------------

:CheckPersistentDrives

; Determine persistent drive letters in use on all systems.
; Can also delete persistent drives - uncomment ';;;' lines.
; DECREMENTING index is most efficient to ensure all removed.
; -------------------------------------------------------------------------

; ** Declare variables as LOCAL (DIM, script-specific) or GLOBAL (KiX-session)
; NOTE: $PersDrv = tmp value of persistent drives in registry $DrvPers = list of all found persistent drives
DIM $PersChk, $PersDrv, $PersErr, $PersKey, $PersShr, $TmpAll, $TmpDelPersDrv, $TmpHomeShr
GLOBAL $DrvPers
$DrvPers = ""
$TmpDelPersDrv = N

IF ($InWin = 1) $PersKey = "HKEY_CURRENT_USER\Network"
ELSE $PersKey = "HKEY_CURRENT_USER\Network\Persistent"
ENDIF

; ** Get count of total existing entries under this key
$x=-1
DO
$x=$x+1
$RC = ENUMKEY ($PersKey, $x)
IF ($RC + ":" = $HomeDrv) ; ** Is the home drive letter in list of persistent drives?
$HomeChk = P
ENDIF
UNTIL @ERROR <> 0

; ** After checking persistent drive entries for home drive letter, verify access to home drive now
IF EXIST ("$HomeDrv\*.*") <> 0 AND ($HomeChk <> P)
$DrvArrayLtr[$DrvArrayIdx] = $HomeDrv ; ** Populate array of known mapped resources
$DrvArrayShr[$DrvArrayIdx] = $HomeFullShr
$DrvArrayIdx = $DrvArrayIdx+1
$HomeChk = Y
$wri = WRITELINE (1, "Verified access to users home drive $HomeDrv $HomeSvr\$HomeShr" + $CR)
ENDIF

; ** Only continue if persistent drives are found
IF ($x=0)
$Status = $OK
$wri = WRITELINE (1, "Verified no persistent drives defined" + $CR)
GOTO "MapNetworkDrives"
ENDIF

$x2=($x-1) ; ** Last value for 'x' will be error (one greater than necessary)
DO
$PersDrv = UCASE (ENUMKEY ($PersKey, $x2))
$PersShr = UCASE (READVALUE ("$PersKey\$PersDrv", "RemotePath"))
SELECT
CASE LEN ($PersShr) < 5 ; ** 5 characters minimum length for a valid persistent resource (i.e \\X\Y)
$Msg = "Error - invalid persistent drive value in registry ($PersKey\$PersDrv, data: $PersShr)"
$TmpDelPersDrv = Y
CASE ($PersDrv + ":" = $HomeDrv) AND ($PersShr = $HomeSvr + "\" + $HomeShr)
$Msg = "Error - persistent drive $PersDrv: $PersShr matches users Home drive and share - persistent drive will be removed from registry"
$TmpDelPersDrv = Y
CASE ($PersDrv + ":" = $HomeDrv)
$Msg = "Error - persistent drive $PersDrv: $PersShr matches users Home drive but not Home share - persistent drive will be removed from removed from registry"
$TmpDelPersDrv = Y
CASE (1)
; ** Confirm can actually access the persistent shared resource
$PersChk = EXIST ("$PersDrv:\*.*")
SELECT
CASE (@ERROR = 0) AND ($PersChk <> 0) $Msg = "Verified access to persistent drive $PersDrv: $PersShr"
CASE (@ERROR = 3) AND ($OS = "Win9X") $Msg = "Verified persistent drive $PersDrv: $PersShr (Not accessible at logon script processing for $OSAbv)"
CASE (@ERROR = 0) $Msg = "Error - verify access to persistent drive $PersDrv: $PersShr (check: $PersChk)"
CASE (INSTR ($PersShr, "\\SOURCECONTROL") <> 0)
$Msg = "Error @ERROR attempting to verifying access to persistent drive $PersDrv: $PersShr (@SERROR)"
CASE ($PersChk <> 0) $Err = $Err+1 $Msg = "Error @ERROR after verifying access to persistent drive $PersDrv: $PersShr (@SERROR / check: $PersChk)"
CASE (1) $Err = $Err+1 $Msg = "Error @ERROR attempting to verifying access to persistent drive $PersDrv: $PersShr (@SERROR)"
ENDSELECT

; ** Populate array of known mapped resources for cross referencing
$DrvArrayLtr[$DrvArrayIdx] = $PersDrv
$DrvArrayShr[$DrvArrayIdx] = $PersShr
$DrvArrayIdx = $DrvArrayIdx+1
ENDSELECT
$wri = WRITELINE (1, "$Msg" + $CR)

; ** Only delete persistent drives based upon flag set in seperate INI file, or if persistent also the home drive
SELECT
CASE ($DelPersDrv = Y) OR ($TmpDelPersDrv = Y)
$con = DELKEY ("$PersKey\$PersDrv")
IF (@ERROR = 0)
$Msg = "Successfully removed persistent drive $PersDrv:"
ELSE
$DrvPers = $DrvPers + $PersDrv
$Err = $Err+1
$Msg = "Error @ERROR removing persistent drive $PersDrv: (@SERROR)"
ENDIF
$wri = WRITELINE (1, "$Msg" + $CR)
CASE ($PersChk <> "") $DrvPers = $DrvPers + $PersDrv ; ** Persistent drive was accessable
CASE ($OS = "Win9X") $DrvPers = $DrvPers + $PersDrv ; ** Persistent drives can not be checked for Win9X, so assume accessible
CASE (1)
;; $DrvPers = $DrvPers + $PersDrv
;; $wri = WRITELINE (1, "Error - can not verify access to persistent drive (PersChk: $PersChk / Del: $DelPersDrv / TmpDel: $TmpDelPersDrv)" + $CR)
ENDSELECT

$TmpDelPersDrv = N
$x2=$x2-1
UNTIL $x2 < 0
$DrvAll = $DrvAll + $DrvPers


; -------------------------------------------------------------------------

:MapNetworkDrives

; Map network data drives to resources defined in 'mapdrives.kix' file
; -------------------------------------------------------------------------

; ** Declare variables as LOCAL (DIM, script-specific) or GLOBAL (KiX-session)
DIM $Disp, $LtrErr, $MapChk, $MapErr, $TmpDrv, $TmpShr
GLOBAL $DrvLtrFound, $DrvMapFound, $MapDrv, $MapShr

$ErrorMsg = "Error mapping network drives on your workstation. A system administrator has been notified."
$DelErr = N ; ** Bucket track errors attempting to delete existing mapped network drive
$LtrErr = N ; ** Bucket to track errors due to drive-letter conflicts
$MapChk = "" ; ** Bucket to confirm mapping worked
$MapDrv = "" ; ** Hold array value for drive letter to map from 'mapdrives_<domain>.kix'
$MapErr = "" ; ** Bucket to note error mapping each drive
$MapSer = "" ; ** Bucket to note error mapping each drive SERROR message
$MapShr = "" ; ** Hold array value for drive share to map to from 'mapdrives_<domain>.kix'
$TmpMap = ""

CALL "$CallKix\mapdrives_" + "$LDom.kix" ; ** Load array with domain/office-specific drive mapping values
IF ($DrvIdx=0)
$wri = WRITELINE (1, "Verified no network drives to map" + $CR)
$Status = $OK
RETURN
ENDIF

$DrvIdxChk=0 ; ** Counter to compare with map drive index count from 'mapdrives_<domain>.kix'
DO
IF $Group[$DrvIdxChk]
$MapDrv = $Drive[$DrvIdxChk]
$MapShr = $Share[$DrvIdxChk]

; ** Confirm drive letter chosen available for mapping (uses results of sections 'CheckLocalDrives' and 'CheckPersistentDrives' above)
$TmpDrv = SUBSTR ($MapDrv, 1, 1) ; ** Change 'H:' to 'H'
SELECT
CASE ($MapDrv = $HomeDrv) AND ($HomeDrv = "Undefined") ; ** Home drive not configured for user in Windows Domain
$MapChk = N
$MapErr = 0
$MapDrv = "" ; ** Null value for logging
$MapShr = "" ; ** Null value for logging
$Msg = "Home directory undefined for user $UserID:"
GOTO "WriteMapLog"
CASE ($MapDrv = "") OR ($MapShr = "") ; ** Blank values for MapDrv or MapShr variables - abort mapping routine
$MapChk = N
$MapErr = 0
$Msg = "blank values for drive or share:"
GOTO "WriteMapLog"
CASE ($MapDrv = $HomeDrv) AND ($HomeChk = Y) ; ** Home drive access already exists, access checked and logged - no script mapping necessary
$DrvAll = $DrvAll + $TmpDrv
GOTO "WriteMapLog" ; ** Go here to write screen display for end-user; no logging performed
CASE INSTR ($DrvLocl, $TmpDrv) <> 0 ; ** Drive letter to map found in list of local ESDI/SCSI devices - abort mapping this resource
;; $Err = $Err+1 ; ** Should error alerts be generated?
$LtrErr = Y
$Msg = "Error - drive letter $MapDrv in use on system as local drive. Remapping to $MapShr will be aborted"
GOTO "WriteMapLog"
CASE (1)
GOSUB "CheckMappedDrives"
SELECT
CASE ($DrvMapFound = DP) ; ** Persistent drive already mapped to this share - delete persistent drive, continue mapping
$wri = WRITELINE (1, "$Msg" + $CR)
CASE ($DrvMapFound = NM) ; ** Network drive and share already mapped via logon script - abort mapping
$LtrErr = Y
GOTO "WriteMapLog"
CASE ($DrvMapFound = PM) ; ** Persistent drive already mapped to another share - abort mapping
$Err = $Err+1
$LtrErr = Y
GOTO "WriteMapLog"
CASE ($DrvMapFound = LM) ; ** Network drive mapped to another share - delete current mapping, continue new mapping
ENDSELECT
ENDSELECT

; ** Delete current connection if exists, map drive, then confirm user can actually access the newly mapped drive
; ** Only update list of in-use drives (DrvAll) if can properly access network drive
IF (EXIST ("$MapDrv\*.*") = 1)
USE $MapDrv /DELETE /PERSISTENT
IF (@ERROR <> 0)
$DelErr = Y
$Msg = "Error @ERROR deleting existing mapped drive $MapDrv. Remapping to $MapShr will be aborted (@SERROR)"
GOTO "WriteMapLog"
ENDIF
ENDIF

USE $MapDrv $MapShr
$MapErr = @ERROR
$MapSer = @SERROR
SELECT
CASE ($MapErr = 0) AND (INSTR ($Share[$DrvIdxChk], "_Zip") <> 0) ; ** Mappings to Zip drives will not always find disk in the drive. Assume proper mapping
$DrvAll = $DrvAll + $TmpDrv
$MapChk = Y
CASE ($MapErr = 0) ; ** Successfull mapping, confirm access to resource
$MapChk = EXIST ("$MapDrv\*.*")
IF (@ERROR = 0)
IF ($MapDrv = $HomeDrv)
$HomeMap = Y
$wri = WRITELINE (1, "Verified access to mapped home drive $MapDrv $MapShr" + $CR)
ENDIF
$DrvAll = $DrvAll + $TmpDrv
$MapChk = Y
ENDIF
CASE ($MapErr = 85) AND ($OS = "WinNT") ; ** Attempted mapping using Local device (WinNT can not enumerate)
$DrvAll = $DrvAll + $TmpDrv
$LtrErr = Y
$wri = WRITELINE (1, "Error $MapErr mapping drive $MapDrv to $MapShr ($MapSer)" + $CR)
CASE (1) ; ** All other errors pass through to next select statement
ENDSELECT

; ** Populate array of known mapped resources for cross referencing
$DrvArrayLtr[$DrvArrayIdx] = $MapDrv
$DrvArrayShr[$DrvArrayIdx] = $MapShr
$DrvArrayIdx = $DrvArrayIdx+1

:WriteMapLog
; ** Display results on console for users benefit
$Row = $Row + 1
? " " + $MapDrv + " $MapShr"
SELECT
CASE ($HomeChk = Y) OR ($HomeMap = Y) AT ($Row,70) " OK" ; ** Verified users home drive access (modified Msg for logging)
CASE ($MapErr = 0) AT ($Row,70) " OK" ; ** No mapping problems
$Msg = "mapped drive"
CASE ($DrvMapFound = Y) AT ($Row,70) " OK" ; ** Resource already mapped, identical mapping routine skipped
CASE ($MapChk = N) AND ($MapErr = 1) ; ** Invalid MapDrv and/or MapShr values
CASE ($DelErr = Y) AT ($Row,70) "Error" ; ** Error deleting existing mapped drive
CASE ($LtrErr = Y) AT ($Row,70) "Skipped" ; ** Drive mapping letter in use as local/persistent drive
CASE (1) AT ($Row,70) "Error" ; ** All other mapping errors
$Err = $Err+1
$LtrErr = Y
$Msg = "Error $MapErr mapping drive $MapDrv to $MapShr ($MapSer / Drv: $MapDrv / Shr: $MapShr)"
ENDSELECT

; ** Write log file after confirming drive mapping success/failure by end-user ability to access the mapped drive.
SELECT
CASE ($DelErr = Y) OR ($LtrErr = Y)
CASE ($HomeChk = Y) OR ($HomeMap = Y) GOTO "ResetMappingVars" ; ** No Msg value to write
CASE ($MapErr = 0) AND ($MapChk = Y) $Msg = "Verified access to $Msg $MapDrv $MapShr"
CASE ($MapErr = 0) $Msg = "Unconfirmed: $Msg $MapDrv $MapShr"
CASE (1)
IF ($MapSer = "") $Msg = "Error $Msg $MapDrv $MapShr (@SERROR)"
ELSE $Msg = "Error $Msg $MapDrv $MapShr ($MapSer)"
ENDIF
ENDSELECT
$wri = WRITELINE (1, "$Msg" + $CR)

:ResetMappingVars
; ** Reset in-use variables for next loop routine
$DelErr = N
$HomeChk = ""
$HomeMap = ""
$LtrErr = N
$MapChk = ""
$MapErr = ""
$MapSer = ""
ENDIF

$DrvIdxChk=$DrvIdxChk+1
UNTIL $DrvIdxChk=$DrvIdx

GOSUB "AlphaDriveLetters"

; ** Not necessary to always print this info (2002.02.07 Bill L)
IF ($OS <> "WinNT") $Msg = "Verified all drive letters in use: $DrvAll"
ELSE $Msg = "Windows NT drive letters in use: $DrvAll"
ENDIF
$wri = WRITELINE (1, "$Msg" + $CR)
$Row = $Row + 1
RETURN



; //////////////////////////////////////////////////////////////////////////////////////////////
;
; REUSED COMPONENTS CALLED FROM ABOVE
;
; //////////////////////////////////////////////////////////////////////////////////////////////


; -------------------------------------------------------------------------

:CheckMappedDrives

; Check array of mapped resources to see if this resource already in use
; -------------------------------------------------------------------------

; ** Declare variables as LOCAL (DIM, script-specific) or GLOBAL (KiX-session)
DIM $DrvArrayIdxChk
GLOBAL $TmpArrayLtr, $TmpArrayShr

$DrvMapFound = N
$DrvArrayIdxChk = 0
DO
$TmpArrayLtr = $DrvArrayLtr[$DrvArrayIdxChk]
$TmpArrayShr = $DrvArrayShr[$DrvArrayIdxChk]
IF INSTR ("$TmpArrayLtr", ":") = 0 ; ** Confirm drive letter variable has colon
$TmpArrayLtr = $TmpArrayLtr + ":"
ENDIF

SELECT
CASE ($MapDrv = $TmpArrayLtr) AND ($MapShr = $TmpArrayShr) AND INSTR ($DrvPers, $TmpDrv) <> 0 ; ** Drive/Share mapping exists as as persistent drive
$DrvArrayIdxChk = $DrvArrayIdx
$DrvMapFound = DP
$Msg = "Verified drive $TmpArrayLtr $TmpArrayShr already mapped as a persistent drive. Persistent mapping will be removed, remapping to $MapDrv $MapShr will continue."
CASE ($MapDrv = $TmpArrayLtr) AND ($MapShr = $TmpArrayShr) ; ** Drive/Share mapping exists, not persistent
$DrvArrayIdxChk = $DrvArrayIdx
$DrvMapFound = NM
$Msg = "Verified network drive exists - $TmpArrayLtr $TmpArrayShr - remapping will be aborted."
CASE ($MapDrv = $TmpArrayLtr) AND INSTR ($DrvPers, $TmpDrv) <> 0 ; ** Drive mapped as persistent, share different
$DrvArrayIdxChk = $DrvArrayIdx
$DrvMapFound = PM
$Msg = "Error - verified $TmpArrayLtr $TmpArrayShr is a persistent drive. Remapping to $MapDrv $MapShr will be aborted"
CASE ($MapDrv = $TmpArrayLtr) ; ** Drive mapped, not persistent, share different
$DrvArrayIdxChk = $DrvArrayIdx
$DrvMapFound = LM
$wri = WRITELINE (1, "Error - verified $TmpArrayLtr $TmpArrayShr already a mapped drive. Remapping to $MapDrv $MapShr will continue" + $CR)
CASE ($MapShr = $TmpArrayShr) AND INSTR ($DrvPers, SUBSTR ($TmpArrayLtr, 1, 1)) <> 0 ; ** Share mapped with different persistent drive
$wri = WRITELINE (1, "Verified $MapDrv $MapShr resource already mapped with persistent drive $TmpArrayLtr $TmpArrayShr" + $CR)
CASE ($MapShr = $TmpArrayShr) ; ** Share mapped with different drive, not persistent
$wri = WRITELINE (1, "Verified $MapDrv $MapShr resource already mapped as $TmpArrayLtr $TmpArrayShr" + $CR)
ENDSELECT
$DrvArrayIdxChk = $DrvArrayIdxChk+1
UNTIL ($DrvArrayIdxChk >= $DrvArrayIdx)
RETURN


; -------------------------------------------------------------------------

:AlphaDriveLetters

; Arrange a list of drive letters alphabetically to ease log viewing
; -------------------------------------------------------------------------

; ** Declare variables as LOCAL (DIM, script-specific) or GLOBAL (KiX-session)
DIM $ChkLen2, $Idx1, $Idx2, $TmpAll1, $TmpAll2, $TmpDrv1, $TmpDrv2, $TmpLen1, $TmpLen2

IF LEN ($DrvAll) = 1 RETURN ENDIF
$TmpAll1 = ""
$TmpLen1 = LEN ($DrvAll)
$Idx1=0
DO
$Idx1=$Idx1+1
$TmpDrv1 = SUBSTR ($DrvAll, $Idx1, 1)
IF ($Idx1 = 1) $TmpAll1 = $TmpDrv1
ELSE
$Idx2=0
$TmpAll2 = ""
DO
$Idx2=$Idx2+1
$TmpLen2 = LEN ($TmpAll1)
$TmpDrv2 = SUBSTR ($TmpAll1, $Idx2, 1)
SELECT
CASE ($TmpDrv2 >= 0) AND ($TmpDrv2 <= 9) ; ** Do not include non-alpha values
CASE ($TmpDrv1 < $TmpDrv2) AND ($Idx2 = 1) $TmpAll2 = $TmpDrv1 + $TmpAll1
$Idx2 = $TmpLen2
CASE ($TmpDrv1 < $TmpDrv2) AND ($Idx2 <= $TmpLen2) $TmpAll2 = $TmpAll2 + $TmpDrv1 + SUBSTR ($TmpAll1, $Idx2, LEN ($TmpAll1))
$Idx2 = $TmpLen2
CASE ($TmpDrv1 > $TmpDrv2) AND ($Idx2 < $TmpLen2) $TmpAll2 = $TmpAll2 + $TmpDrv2
CASE ($TmpDrv1 > $TmpDrv2) AND ($Idx2 = $TmpLen2) $TmpAll2 = $TmpAll2 + $TmpDrv2 + $TmpDrv1
CASE ($TmpDrv1 = $TmpDrv2) AND INSTR ($TmpAll2, $TmpDrv1) <> 0 ; ** Explicitly catch duplicate letters from being listed here
CASE (1)
ENDSELECT
UNTIL ($Idx2 = $TmpLen2) OR ($TmpLen2 = 0)
$TmpAll1 = $TmpAll2
ENDIF
UNTIL ($Idx1 = $TmpLen1) OR ($TmpLen1 = 0)
$DrvAll = $TmpAll1
RETURN