#47621 - 2003-11-06 08:39 PM
Add/Delete printers based upon existing INI file?
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
I'd like to modify this script so that it doesn't just add printers from the PRINTSETUP.INI file IF there are no printers, but to always duplicated this file. Adding AND deleting based on the INI file contents.
code:
;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 ;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 ;********** Beginning of printer info gathering script $loc='HKEY_CURRENT_USER\Network\LPT1' $reg='HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion' $dev=$reg+'\Devices' $nprt=split(READVALUE($reg+'\Windows','Device'),',')[0] $sysdrv=SUBSTR('%WINDIR%',1,2) dim $priReg, $x, $i, $rc, $ps ;********** Set Printsetup.ini file location $ps=('\\mrh-01\prtlog$') $ps=($ps+'\@wksta') IF 0=EXIST($ps) MD $ps ENDIF $ps=$ps+'\Printsetup.ini' $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 default printer to file $rc=WRITEPROFILESTRING($ps,'Printers','Default',$nprt) USE LPT1: /delete /persistent USE LPT1: $nprt /persistent CASE $nprt='' AND EXIST($ps) ;No default printer, load printers from saved info FOR EACH $key IN split(readprofilestring($ps,'Printers',''),chr(10)) $nul=addprinterconnection(readprofilestring($ps,'Printers',$key)) NEXT $nprt=READPROFILESTRING($ps,'Printers','Default') $rc=SETDEFAULTPRINTER($nprt) USE LPT1: $nprt /persistent CASE NOT INSTR($nprt,'\\') ;Local printer default, remove network mapping USE LPT1: /delete /persistent ENDSELECT
Resulting PRINTSETUP.INI file in directory called @wksta (each workstation's name) --------------------- [Printers] 1=\\mrh-01\q-mis2 2=\\mrh-01\q-mis1 3=\\mrh-01\q-mis2-color Default=\\mrh-01\q-mis2
This line indicates that only if no printers exist, should the ini file be read. This is the line that I would like to replace with a line that does a comparison of current print setup and the Printsetup.ini file and change if not the same.
code:
CASE $nprt='' AND EXIST($ps) ;No default printer, load from saved info FOR EACH $key IN split(readprofilestring($ps,'Printers',''),chr(10)) $nul=addprinterconnection(readprofilestring($ps,'Printers',$key)) NEXT $nprt=READPROFILESTRING($ps,'Printers','Default') $rc=SETDEFAULTPRINTER($nprt) USE LPT1: $nprt /persistent
I would remove the part that creates the original file (assuming that I have a file for each workstation or will create one manually):
code:
CASE INSTR($nprt,'\\') ;Write default printer to file $rc=WRITEPROFILESTRING($ps,'Printers','Default',$nprt) USE LPT1: /delete /persistent USE LPT1: $nprt /persistent
[ 06. November 2003, 20:42: Message edited by: tjcarst ]
|
|
Top
|
|
|
|
#47625 - 2003-11-12 11:36 PM
Re: Add/Delete printers based upon existing INI file?
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
I couldn't get unmapprinters.udf to work with my ini file.
Using enumprinter connections to keep the installed printers mirrored to a file would be a new direction for me to explore.
If existing workstation printers are not like file, add/remove/set default as necessary. I'll start on this and see where it gets me.
Probably not even out of the driveway
tjcarst
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 696 anonymous users online.
|
|
|