Dim $sDOMAIN,$sSpooler,$sDone,$iDefaultDone
$sDOMAIN="westcare"
$sSpooler="\\wcps1\"
$sDone=@CRLF
$iDefaultDone=0
;set index to 0 for looping through groups
$iIndex = 0
;get first group name
$sGroup=EnumGroup($Index)
While Len($sGroup) AND @ERROR=0
;if group name starts with print- or printd-
If (InStr($sGroup,$sDOMAIN+"\print-")=1) OR (InStr($sGroup,$sDOMAIN+"\printd-")=1)
$sPrinter=SubStr($sGroup,InStr($sGroup,"-")+1) ; Note, this won't work if you have "-" in the domain name
If InStr($sDone,@CRLF+$sPrinter+@CRLF)
; Printer has already been added - no point in doing it again.
Else
; Add printer and make sure it’s successful
If AddPrinterConnection($sSpooler+$sPrinter)
; Display error message and text
"Error Adding Printer: "+$sPrinter+@CRLF
"Error: "+@SERROR+@CRLF
Else
"Added printer: "+$sPrinter+@CRLF ; Display success message
$sDone=$sDone+$sPrinter+@CRLF ; Record success
EndIf
EndIf
; If printer has been added OK AND is default AND a default has not been set already...
If InStr($sDone,@CRLF+$sPrinter+@CRLF) AND InStr($sGroup,$sDOMAIN+"\printd-")=1 AND $iDefaultDone=0
If SetDefaultPrinter($s$sPrinter)
; Display error message and text
"Error Setting Default Printer: "+$sPrinter+@CRLF
"Error: "+@SERROR+@CRLF
Else
"Set default to: "+$sPrinter+@CRLF ; Display success message.
$iDefaultDone=1
EndIf
EndIf
EndIf
$iIndex=$iIndex+1 ;increase the loop counter by 1
$sGroup=EnumGroup($iIndex) ;get next group name
; loop until end of groups list
Loop