Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
{Edit - Code completed!!} Looking at doing a re-write of the FAQ for the "Default Printer." While the newest version works great for one printer.. What happens when a person has multiple network printers and they get a new machine? I started think about this as this became evident with the recent printer migration we were under. I would welcome any feedback/comments in regards to this script re-write.
CLS BREAK ON ;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 $local='HKEY_CURRENT_USER\Network\LPT1' $reg='HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion' $dev=$reg+'\Devices' $ptr=$reg+'\Windows' $nptr=READVALUE($ptr,'Device') $lpt=SUBSTR($nptr,1,InStr($nptr,',')-1) $sysdrv=SUBSTR('%WINDIR%',1,2) IF EXIST('H:') $ps='H:\Scripts_DO_NOT_DELETE\Printsetup.ini' IF 0=EXIST('H:\Scripts_DO_NOT_DELETE') MD 'H:\Scripts_DO_NOT_DELETE' ENDIF ELSE $ps=$sysdrv+'\Scripts\Printsetup.ini' IF 0=EXIST($sysdrv+'\Scripts') MD $sysdrv+'\Scripts' ENDIF ENDIF
;Ref. - http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000221 ;Thanks Howard! $index=0 DIM $keyname[$index] IF KeyExist($dev) AND EXIST($ps) DO $x=ENUMVALUE($dev,$index) $error=@error IF NOT $error AND $index>Ubound($keyname) REDIM PRESERVE $keyname[$index] ENDIF IF NOT $error $keyname[$index]=$x IF INSTR($x,'\\') ;REMOVE THE PRINTER SETTINGS FILE AS PRINTERS MAYBE ADDED/REMOVED DEL $ps ENDIF $index=$index+1 ENDIF UNTIL $error ELSE $keyname[0]='' ENDIF
;THIS CAPTURES ALL NETWORK PRINTERS INSTALLED $index=0 IF KeyExist($dev) DO $x=ENUMVALUE($dev,$index) $error=@error IF NOT $error AND $index>Ubound($keyname) REDIM PRESERVE $keyname[$index] ENDIF IF NOT $error $keyname[$index]=$x IF INSTR($x,'\\') AND $x<>$lpt $rc=WRITEPROFILESTRING($ps,'Printers',$index,$x) ENDIF $index=$index+1 ENDIF UNTIL $error ELSE $keyname[0]='' ENDIF
;CHECK FOR THE DEFAULT PRINTER SELECT CASE INSTR($nptr,'\\') ;WRITE THE PRINTER TO THE CONFIG AS THE LOCAL NET PRINTER MAY HAVE CHANGED $rc=WRITEPROFILESTRING($ps,'Printers','Default',$lpt) $lpt1=READPROFILESTRING($ps,'Printers','Default') $rc=ADDPRINTERCONNECTION($lpt1) $rc=SETDEFAULTPRINTER($lpt1) USE LPT1: /delete /persistent USE LPT1: $lpt1 /persistent CASE $nptr='' AND EXIST($ps) $lpt1=READPROFILESTRING($ps,'Printers','Default') $rc=ADDPRINTERCONNECTION($lpt1) $rc=SETDEFAULTPRINTER($lpt1) USE LPT1: $lpt1 /persistent ;Ref. - http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=1&t=006790 ;Thanks Doc for the ideas and Lonkero for the fixes! FOR EACH $key IN split(readprofilestring($ps,'Printers',''),chr(10)) IF $key<>'Default' $nul=addprinterconnection(readprofilestring($ps,'Printers',$key)) ENDIF NEXT CASE ;LOCAL PRINTER INSTALLED, BUT WE WANT TO REMOVE ANY NETWORK MAPPING INSTR($nptr,'LPT') AND READVALUE($local,'RemotePath')<>'' USE LPT1: /delete /persistent ENDSELECT RETURN
Thanks,
Kent [ 12. April 2003, 18:33: Message edited by: kdyer ]
|