Page 1 of 1 1
Topic Options
#47621 - 2003-11-06 08:39 PM Add/Delete printers based upon existing INI file?
tjcarst Offline
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
#47622 - 2003-11-07 03:28 AM Re: Add/Delete printers based upon existing INI file?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
now, what you really want is actually a "restriction" setup?
a script that does forced mapping according to that file?

if so, think you shouldn't use this script base at all as it does not need to be this complex.

if you want something else, could you explain little more...
_________________________
!

download KiXnet

Top
#47623 - 2003-11-07 04:43 AM Re: Add/Delete printers based upon existing INI file?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or use UnmapPrinters() - Removes mapped printers not listed in an .INI file as a model for your map/unmap function.
_________________________
There are two types of vessels, submarines and targets.

Top
#47624 - 2003-11-07 05:25 AM Re: Add/Delete printers based upon existing INI file?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I think the proper way would be to use something like enumprinterconnections() and then compare the results with ini-file.

unmapprinters() works as a base but you need to add the code for adding if in ini but not mapped.
_________________________
!

download KiXnet

Top
#47625 - 2003-11-12 11:36 PM Re: Add/Delete printers based upon existing INI file?
tjcarst Offline
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 [Wink]

tjcarst

Top
#47626 - 2003-11-13 04:13 AM Re: Add/Delete printers based upon existing INI file?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
quote:
I couldn't get unmapprinters.udf to work with my ini file.
UnMapPrinters works with a specific .INI file format which is defined in the UDF Header.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.053 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org