I have a similar system, although my groups are name "MAP x share", where "share" is a share mnemonic, and "x" is the drive letter that I want to map it it. I prefer this becasue it keeps the drive letters consistent.
The following code should work for you:
Code:
Break ON
$=SetOption("Explicit","ON")
Dim $sHidden, $sFS1, $sFS2, $sFS3
Dim $iIndex, $sGroup, $sGroupRN
Dim $sDriveList
; Define constants
$sHidden="$$"
$sFS1="bar.com"
$sFS2="foo.com"
$sFS3="other.com"
$sDriveList="S:I:J:"
$iIndex=0 $sGroup=EnumGroup($iIndex)
While Not @ERROR AND $sGroup <> ""
; Drop domain name.
$sGroupRN=SubStr($sGroup,InStr($sGroup,"\")+1)
Select
Case $sGroupRN="_PTK"
If MapDrive("N:","\\"+$sFS3+"\"+"PTKSHARE"+$sHidden)
"ERROR: Cannot map drive 'N:' to path '"+"\\"+$sFS3+"\PKTSHARE"+$sHidden+"'"+@CRLF
"REASON: ["+@ERROR+"] "+@SERROR+@CRLF
EndIf
Case Left($sGroupRN,1)="_"
; Handle special group mappings.
If $sDriveList
If MapDrive(Left($sDriveList,2),"\\"+$sFS2+"\"+SubStr($sGroupRN,2)+$sHidden)
"ERROR: Cannot map drive '"+Left($sDriveList,2)+"' to path '"+"\\"+$sFS2+"\"+SubStr($sGroupRN,2)+$sHidden+"'"+@CRLF
"REASON: ["+@ERROR+"] "+@SERROR+@CRLF
Else
$sDriveLetter=SubStr($sDriveLetter,3)
EndIf
Else
"ERROR: Exhausted drive letters."+@CRLF
" Cannot map share for group "+$sGroup+@CRLF
EndIf
Case "Default"
"No special handling for group "+$sGroup+@CRLF
EndSelect
$iIndex=$iIndex+1 $sGroup=EnumGroup($iIndex)
Loop
Exit 0
Function MapDrive($d,$p)
Use $d /delete /persistent
Use $d $p
$MapDrive=@ERROR
Exit $MapDrive
EndFunction
This will map _PTK to a hardcoded path (on drive N:).
The first group starting "_" (which is not _PTK) will be mapped to S:, the next to I:, and the third to "J:". Any "_" group after that will issue an error message.
If you want to add more drive letters to the available pool, just change the $sDriveLetters variable.