Page 2 of 2 <12
Topic Options
#46069 - 2003-10-10 06:05 PM Re: Printer mapping - modification of Howard's script based on group membership
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
This kix script generates a log file, but I do not like that it generates the name of the printer as installed on the pc and not the actual \\server\share name. I could probably change this using the ini file.

</font><blockquote><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">break on

;********** Prevent logon script on server *********
call @ScriptDir+'\osid.udf'

$os=osid()
if $os[2]<>'Workstation'
exit 0
endif

;********** Beginning of printer info gathering script *********
$PrtLog="\\ps-01\Prtlog$"
$PrtLog=$PrtLog+"\@wksta"+"_"+"@userid"
;$PrtLog=$PrtLog+"\@wksta"
if 0=exist($PrtLog)
MD $PrtLog
endif
$PrtLog=$Prtlog+"\default.log"
call "@scriptdir\getdefaultprinter.udf"

$rc=Get_Default_printer()

$rc=WriteLog2($PrtLog,Get_Default_Printer(),1)

;if (RedirectOutput("$PrtLog",1) = 0)
;endif


;-------------------------------------------------------------------------------;FUNCTION WriteLog2()
;
;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com)
;
;ACTION Generic logging facility for scripts. Appends log entry to a file with an
; optional TimeStamp.
;
;SYNTAX WriteLog2($File, $text, [0|1])
;
;PARAMETERS $File (Required) - String value
; $text (Required) - String value
; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0)
;
;
;REMARKS This function writes (appends) an optionally time stamped log entry to the file
; defined in function. This function searches for the first unused file handle,
; open the file, and write the entry. The file handle is then closed. When the
; function is unable to perform its it write the error is displayed in a message box.
;
;RETURNS Nothing
;
;DEPENDENCIES None
;
;EXAMPLES WriteLog2("junk.txt","This is a test")
; WriteLog2("junk.txt","This is a test",0)
; WriteLog2("junk.txt","This is a test",1)
;
Function WriteLog2($File, $Text, optional $TimeStamp)
dim $RC, $File, $text, $FH, $TimeStamp
$FH=1
$RC=Open ($FH, $File, 5)
while $RC = -3
$FH=$FH +1
$RC=Open ($FH, $File, 5)
Loop
Select
Case $RC=0
if ($TimeStamp=1)
$TimeStamp = @Date + " " + @Time + " - "
else
$TimeStamp = ""
endif
$RC=Writeline ($FH, $TimeStamp + $Text + @CRLF)
$RC=Close ($FH)
Case $RC=-2
$text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=-1
$text = "WriteLog2: Invalid file name ($File) specified for log file."
$RC=MessageBox ($text,"Script Error",48)
Case $RC=>0
$text = "System Error($RC) while attempting to open log file ($File)."
$RC=MessageBox ($text,"Script Error",48)
Endselect
EndFunction[/code]</blockquote><font size="2" face="Verdana, Helvetica, sans-serif">sample contents of default.log
-------------------------
2003/09/24 10:05:43 - Q-MIS2 IP,winspool,Ne01:
2003/09/24 10:11:09 - NONE
2003/09/24 10:13:02 - Fax,winspool,Ne00:
--------------------------


Edited by tjcarst (2007-09-12 10:15 PM)

Top
#46070 - 2003-10-10 06:11 PM Re: Printer mapping - modification of Howard's script based on group membership
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
I have the part figured out that generates the log and records time, userid and printer.
Top
#46071 - 2003-10-10 06:15 PM Re: Printer mapping - modification of Howard's script based on group membership
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
I would also like to record if there is a local printer in the ini file. Sometimes we have local deskjets on lpt1, but the primary printer is a network laser. Other times it is th deskjet that is the default. I'd like to record both and set correct printer.

I'd prefer that the ini file is used for all printer add/deletes. If we wanted to delete a printer, do it in the ini file, not on the pc.

Here's the current printsetup.kix that generates my existing ini file.

code:
;********** Prevent logon script on server *********
call @ScriptDir+'\osid.udf'

$os=osid()
if $os[2]<>'Workstation'
exit 0
endif

;********** Prevent logon script for Health Info Mgmt *********
if InGroup ("Medrec Group")
exit 0
endif

;********** Beginning of printer info gathering script *********


;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

$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'+'_'+'@userid')
$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 THE DEFAULT PRINTER TO THE CONFIG
$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, SO WE WANT TO REMOVE NETWORK MAPPING
USE LPT1: /delete /persistent
ENDSELECT

Results of printsetup.kix

[Printers]
1=\\mrh-01\q-mis1
2=\\mrh-01\q-mis2
Default=\\mrh-01\q-mis2

[ 12. October 2003, 21:01: Message edited by: tjcarst ]

Top
#46072 - 2003-10-10 08:46 PM Re: Printer mapping - modification of Howard's script based on group membership
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
sealeopard - I have a post going here where Howard is providing assistance on this issue.

http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=14&t=001201#000022

I just posted this idea - what do you think? I'll test my script and post for you in a bit:

Okay, this may be extra work creating groups, but it may be the easiest way to set the primary printer when there are multiple printers installed.

Create a group specifically for a default printer group. Like DefPrinter_MRH-01_Q-MIS2 and put pcs in this group to get default/only printer of Q-MIS2. Create another group Printer_MRH-01_Q-MIS2 for users that have this additional printer. Use the SetDefaultPrinter in the script to set default printer if group name starts with DefPrinter.

tjcarst

Top
#46073 - 2003-10-10 09:02 PM Re: Printer mapping - modification of Howard's script based on group membership
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Okay here's the script.

It seems to do what I need. I have to create a group for the default printer and a group for secondary printers, but it works, even if a little cumbersome.

tjcarst

code:
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920

call @ScriptDir+'\PriMapState.udf'

;********** Prevent script from running on a server or Win95*********
if @userid = administrator
call @Scriptdir+'\osid.udf'
$os=osid()
if $os[1]='Win95' or $os[2]<>'Workstation'
exit 0
endif
endif

;********** Prevent script from running on Medrec pcs *********
if InGroup ("Medrec Group")
exit 0
endif

;********** Beginning of printer mapping *********

$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")
if @error
? @serror
else
for each $grp In $WS.Groups
$GrpName = $grp.Name

;--- Add and set default printer ---

if left($GrpName,11) = "PrinterDef_"
$defprinter = substr($GrpName,12)
$defprinter = join(split($defprinter,"_"),"\")

if not PriMapState("\\" + $printer)
? "Status - Printer not connected \\"+$printer
$S=AddPrinterConnection("\\" + $printer)
? "Status - Printer added \\"+$printer
? @serror
?
$S=SetDefaultPrinter ("\\" + $defprinter)
? "Status - Default Printer set \\"+$defprinter
? @serror
endif

if PriMapState("\\" + $defprinter)<>2
$S=SetDefaultPrinter ("\\" + $defprinter)
? "Status - Default Printer set \\"+$defprinter
? @serror
endif

endif


;--- Add additional printers ---

if left($GrpName,8) = "Printer_"
$printer = substr($GrpName,9)
$printer = join(split($printer,"_"),"\")

if not PriMapState("\\" + $printer)
? "Status - Printer not connected \\"+$printer
$S=AddPrinterConnection("\\" + $printer)
? "Status - Printer added \\"+$printer
? @serror
?
endif

endif

next

endif


Top
Page 2 of 2 <12


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.056 seconds in which 0.022 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