Richie19Rich77
(Seasoned Scripter)
2002-08-21 02:36 PM
Printing Scripts

Hi all

I have created a printer script that works out what workstation you are working on then sets up the printers, and the option of having your office printer to follow you about.

This might be useful users who move around alot and do not have a dedicated PC.

First of all I run a Computer Startup Script.

;Computer Boot-Up Printer Script

; This line sets the variable $prn to the prnfile.ini file which contains all the workstation names
$prn = "\\QEH-TR\SYSVOL\QEH-TR.STHAMES.NHS.UK\Scripts\prnfile.ini"

$prn1 = READPROFILESTRING("$prn", @wksta, "prn1")
$prn2 = READPROFILESTRING("$prn", @wksta, "prn2")
$defprn = READPROFILESTRING("$prn", @wksta, "default")

open ( 1 ,"%SystemDrive%\Printers.cmd" , 5 )
writeline ( 1 , "\\QEH-TR\SYSVOL\QEH-TR.STHAMES.NHS.UK\SCRIPTS\con2prt /f " +$defprn + " " +$prn1 + " " +$prn2)
close (1)

That references a ini file which looks like this:

[DCENTRE01]
prn1 = /c \\fileprint\3341
;prn2 = /c \\fileprint\3343
default = /cd \\fileprint\3340

[DCENTRE02]
prn1 = /c \\fileprint\3341
;prn2 = /c \\fileprint\3340
default = /cd \\fileprint\3340

[DCENTRE03]
prn1 = /c \\fileprint\3341
;prn2 = /c \\fileprint\3340
default = /cd \\fileprint\3340

Then when the user logs in, the login script will call the printers.cmd file located on the local PC and connect to the 3 nerest printers to that PC.

And the as a optional script, If a user want their Office printer on the printer list I run this script.

;Home Printer Re-Direction Script

$prn = @LDRIVE + "homeprn.ini"

$homeprn = READPROFILESTRING("$prn", @userid, "homeprn")

shell @LDRIVE + "con2prt /c " +$homeprn"

That calls a ini file which looks like this.

[administrator]
homeprn = \\fileprint\opsptr

[richard.farthing]
homeprn = \\fileprint\3044

[tracy.ross]
homeprn = \\fileprint\3341

I work for a Hospital, and this has worked wonders since installing.

Hope it can help someone out.

Richard Farthing


Sealeopard
(KiX Master)
2002-08-21 04:00 PM
Re: Printing Scripts

See also
code:
;-------------------------------------
; map printers based on user groups
;
; Structure of the .INI file:
; [Printer name]
; Printserver = Name of the printserver (might be comma-delimited for redundancy)
; GroupInclude = User groups to be included in the printer connection
; CompExclude = Computers to be excluded from the drive share
; UserInclude = Users to be included in the drive share
; Model = Model of the printer
;-------------------------------------
; UDFs: ATRIM(), ISINCLUDED(), MAPPRINTER()
:NETWORKED_PRINTERS
Dim $printerlist, $printername, $printserver, $printmodel
Dim $GroupInclude, $CompExclude, $UserInclude, $os, $rc

if @INWIN=1
if exist($PRINTERSINI)
? 'Connecting network printers'
$printerlist=readprofilestring($PRINTERSINI,'','')
$printerlist=atrim(split($printerlist,chr(10)))
for each $printername in $printerlist
if len($printername)
$GroupInclude=readprofilestring($PRINTERSINI,$printername,'GroupInclude')
$GroupInclude=atrim(split($GroupInclude,','))
$CompExclude=readprofilestring($PRINTERSINI,$printername,'CompExclude')
$CompExclude=atrim(split($CompExclude,','))
$UserInclude=readprofilestring($PRINTERSINI,$printername,'UserInclude')
$UserInclude=atrim(split($UserInclude,','))

if isincluded($GroupInclude, $CompExclude, $UserInclude)
$printserver=readprofilestring($PRINTERSINI,$printername,'Printserver')
$printserver=atrim(split($printserver,','))
$printmodel=readprofilestring($PRINTERSINI,$printername,'Model')
$rc=mapprinter($printername,$printserver,$printmodel)
endif
endif
next
else
? 'Cannot open printer initialization file '+$PRINTERSINI
endif
else
? 'Automatic printer installation is not supported under '+@PRODUCTTYPE
endif
return

which is part of a modular login script to be found at Modular Login Script (long post, lots of code) and is also used as part of KiXtart Systems Management Server

[ 21. August 2002, 16:04: Message edited by: sealeopard ]