;need to dim vars
Dim $rc
Dim $Location,$Table
Dim $iproom,$ip
Dim $Printer,$DefaultPrinter
Dim $MissingIPprintermapp,$FileShareError
;get the "location"
$Location = Left(@WKSTA, 6)
; printer table is in \\fileserver\share\printertable.ini
; If this is done during a login script, table would be
; \\domain\netlogon\printertable.ini
$Table = '\\fileserver\share\printertable.ini'
;logic should be if cannot read the file, get the error,
if NOT $Printer = ReadProfileString($Table, 'PrinterMapping', $Location)
@SERROR = $FileShareError
else
;else let's set the default printer from it.
$DefaultPrinter=ReadProfileString($Table,'PrinterMapping',split(join$;not done. no brain left. (get the name of the printer)
endif
;now, let's check the room and ip
$iproom=ReadProfileString($Table,'IP-Check',$Location)
$ip=join(split(@ipaddress0,' '),'')
Select
;this case captures if there was an error getting the file
case $FileShareError
'Error! Please report following to you administrator: File share error, ' + @CRLF + $FileShareError ?
;this case catches if the ip and room is a missmatch,
;and could provide the user with the settings to mapp it by "hand"
case $iproom =! $ip
'Something seems to be wrong, contact your administrator,'?
or please enter the name for the printer: ' gets $MissingIPprintermapp ?
$MissingIPprintermapp=rtrim(ltrim($MissingIPprintermapp))
if $MissingIPprintermapp
$rc = AddPrinterConnection('\\printerserver\'+$MissingIPprintermapp)
if $rc
$rc = SetDefaultPrinter($MissingIPprintermapp) ' Setting your printer of choise as default ' ?
else 'error occured! ' + @SERROR + ' ' + @ERROR + ' ' ?
endif
endif
;the nice "default case". If everything worked out, do the mapping
;according to the .ini .
case 1
'Setting up your printer per-default configuration ' ?
If Left(@WKSTA, 6) = $Printer
if NOT $rc = SetDefaultPrinter($DefaultPrinter)
$rc = AddPrinterConnection($Printer)
;Delete the printer.
$rc = DelPrinterConnection($DefaultPrinter)
;Connect the printer.
$rc = AddPrinterConnection($Printer)
;Set the printer as default.
$rc = SetDefaultPrinter($DefaultPrinter)
endif
endif
Else
;Do nothing.
EndIf
EndSelect
/* the ini-file structure
[IP-Check]
be_105=10.105
be_106=10.106
[PrinterMapping]
be_105=\\server\printshare
be_106=\\server\printshare
*/