Ok,
To create an "ini" file, just use Notepad or similar.
The following code is the same as before, but changed to retrieve the printer list from an INI file:
Code:
Break ON
CLS
$sPrinterIni=".\PrinterMap.ini"
$iIndex=0
$iDefaultDone=0
$sGroup=EnumGroup($iIndex)
While $sGroup AND Not @ERROR
; Drop domain
If InStr($sGroup,"\") $sGroup=SubStr($sGroup,InStr($sGroup,"\")+1) EndIf
; Check if there is a printer map for this group
For Each $sPrinter in Split(ReadProfileString($sPrinterIni,"LOCATION "+$sGroup,""),Chr(10))
If $sPrinter
$asPrinterPair=Split(ReadProfileString($sPrinterIni,"LOCATION "+$sGroup,$sPrinter),"|")
"Mapping primary printer path "+$asPrinterPair[0]
If AddPrinterConnection($asPrinterPair[0])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"Mapping alternative printer path "+$asPrinterPair[1]
If AddPrinterConnection($asPrinterPair[1])
" " Color r+/n "*ALSO FAILED*" Color w/n @CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
If Not $iDefaultDone
"Setting printer as default"
If SetDefaultPrinter($asPrinterPair[1])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"ERROR: Could not set printer as default."+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
$iDefaultDone=1
EndIf
EndIf
EndIf
Else
" " Color g+/n "OK" Color w/n @CRLF
"Setting printer as default"
If Not $iDefaultDone
If SetDefaultPrinter($asPrinterPair[0])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"ERROR: Could not set printer as default."+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
$iDefaultDone=1
EndIf
EndIf
EndIf
EndIf
Next
$iIndex=$iIndex+1
$sGroup=EnumGroup($iIndex)
Loop
Exit 0
The way it works is:
1) Iterates through all the groups that the user is a member of.
2) Looks for a section in the "ini" file with a name "[LOCATION group]"
3) For every printer in the section it attempts to connect it, using the first printer that it successfully adds as the default printer.