; -- INITIATE THE FUNCTION..
DEFPRTR
FUNCTION DEFPRTR()
; Re-Write at http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=2;t=004308
; By Kdyer & Lonkero (15th april 2003)
; Re-Write of http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=10;t=000021
;Default Printer Configuration
;This is to capture the Default Printer and get all network defined printers as well
; Ref. http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=1&t=006790
; Ref. http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000221
DIM $prireg,$x,$i,$rc,$ps,$reg,$dev,$nprt,$key
SELECT
CASE
@wksta='MAILROOM1' OR @wksta='MAILROOM2' ; -- MAIL STATION PCS
RETURN
CASE
INSTR(@wksta,'TRAIN') ; -- TRAINING SYSTEMS
USE LPT1: /delete
$rc=ADDPRINTERCONNECTION('\\PSERVER\PRINTER-P18')
SLEEP '0.5'
$rc=SETDEFAULTPRINTER('\\PSERVER\PRINTER-P18')
SLEEP '0.5'
USE LPT1: '\\PSERVER\PRINTER-P18'
RETURN
ENDSELECT
$reg='HKCU\Software\Microsoft\Windows NT\CurrentVersion\'
$dev=$reg+'Devices'
$nprt=split(READVALUE($reg+'Windows','Device'),',')[0]
IF EXIST('H:')
$ps='H:\Scripts_DO_NOT_DELETE'
ELSE
$ps=LEFT('%WINDIR%',2)+'\Scripts'
ENDIF
IF 0=EXIST($ps)
MD $ps
ENDIF
SELECT
CASE
Ltrim(Split(@ipaddress0,'.')[0])+'.'+Ltrim(Split(@ipaddress0,'.')[1])='1.1'
$ps=$ps+'\SITE1.ini'
CASE
Ltrim(Split(@ipaddress0,'.')[0])+'.'+Ltrim(Split(@ipaddress0,'.')[1])='2.2'
$ps=$ps+'\SITE2.ini'
CASE
1
$ps=$ps+'\PRINTSETUP.ini'
ENDSELECT
$i=0
DO
IF '\\'=LEFT($x,2)
$prireg=$prireg+$x
ENDIF
$x=ENUMVALUE($dev,$i)
$i=$i+1
UNTIL @error
IF LEN($prireg)
$rc=WRITEPROFILESTRING($ps,'Printers','','')
$prireg=split($prireg,'\\')
FOR $i=1 TO ubound($prireg)
$rc=WRITEPROFILESTRING($ps,'Printers',$i,'\\'+$prireg[$i])
NEXT
ENDIF
SELECT
CASE
INSTR($nprt,'\\') ;WRITE THE DEFAULT PRINTER TO THE CONFIG
$rc=WRITEPROFILESTRING($ps,'Printers','Default',$nprt)
USE LPT1: /delete /persistent
USE LPT1: $nprt
CASE
$nprt='' AND EXIST($ps) ;NO DEFAULT PRINTER, LOAD PRINTERS FROM SAVED INFO
FOR EACH $key IN split(readprofilestring($ps,'Printers',''),chr(10))
$rc=addprinterconnection(readprofilestring($ps,'Printers',$key))
NEXT
$nprt=READPROFILESTRING($ps,'Printers','Default')
$rc=SETDEFAULTPRINTER($nprt)
USE LPT1: $nprt
CASE
(INSTR($nprt,'Generator') OR INSTR($nprt,'Image Writer')) AND EXIST($ps) ;MS-OFFICE PRINTER(S), LOAD PRINTERS FROM SAVED INFO
FOR EACH $key IN SPLIT(READPROFILESTRING($ps,'Printers',''),chr(10))
$rc=ADDPRINTERCONNECTION(READPROFILESTRING($ps,'Printers',$key))
$rc=SETDEFAULTPRINTER(READPROFILESTRING($ps,'Printers',$key))
; -- Re-Read the Registry Key
$nprt=split(READVALUE($reg+'Windows','Device'),',')[0]
$rc=WRITEPROFILESTRING($ps,'Printers','Default',$nprt)
IF LEFT(READPROFILESTRING($ps,'Printers',$key),2)='\\'
USE LPT1: READPROFILESTRING($ps,'Printers','Default')
ENDIF
NEXT
CASE
NOT INSTR($nprt,'\\') ;LOCAL PRINTER DEFAULT, SO WE WANT TO REMOVE NETWORK MAPPING
USE LPT1: /delete /persistent
ENDSELECT
ENDFUNCTION