Page 2 of 3 <123>
Topic Options
#74454 - 2003-04-14 02:16 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, why 4.20+ rocks?

this code should work just fine with 4.12 or 4.10
_________________________
!

download KiXnet

Top
#74455 - 2003-04-14 02:19 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Shows you things like: Error Line 12 Missing Comma..

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74456 - 2003-04-14 02:22 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Thing that is kind of nagging at me now is if the client has a USB Printer..

For example...

INSTR($nptr,'LPT') AND READVALUE($loc,'RemotePath')<>''

For example, I have installed a Brother MFC 8700 here on the USB port and it shows -
winspool,Ne01:

And not -
winspool,LPT1:

Thanks,

Kent

[ 14. April 2003, 14:25: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74457 - 2003-04-14 02:30 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Think this should cover if the printer is on LPT, USB, etc.
code:
CASE
NOT INSTR($nptr,'\\') AND READVALUE($loc,'RemotePath')<>''
...

Kent

[ 14. April 2003, 14:31: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74458 - 2003-04-14 02:31 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just change it:
if not instr($nprt,'\\')

so, if default is not network printer
_________________________
!

download KiXnet

Top
#74459 - 2003-04-14 02:32 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you don't need:
AND READVALUE($loc,'RemotePath')<>''

at all.
_________________________
!

download KiXnet

Top
#74460 - 2003-04-14 02:37 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Wait a second..

Let's think about this scenario..

They were printing on a network printer and been redirecting LPT1 to the network printer..

They have IT order a new local printer, but they still want access to the network-based color printer.. Shouldn't you check to see if they are re-mapping LPT1 to the network?

Kent

[ 14. April 2003, 14:38: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74461 - 2003-04-14 02:43 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
why you need to know what they do with the default printer as long as you know that it's not network printer?
_________________________
!

download KiXnet

Top
#74462 - 2003-04-14 04:05 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
btw, actually the errorcodes are a lot better in 4.12 and previous if you just use wkix32.exe

they are "broken" in 4.20 and after and lack information.
_________________________
!

download KiXnet

Top
#74463 - 2003-04-14 04:15 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Lonk,

You are right.. It doesn't matter. If we use the NOT INSTR($nptr,'\\') it covers this.

[Embarrassed]

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74464 - 2003-04-14 10:45 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Running into a problem though...

Connected into another workstation after setting my workstation to a have a local printer..

It errors on -
USE LPT1: $lpt1 /persistent

The INI File has:
code:
[Printers]
1=\\printserver\printserver-p19
2=\\printserver\printserver-p27

So, when I login to the other workstation, there is no entry for
code:
[Printers]
1=\\printserver\printserver-p19
2=\\printserver\printserver-p27
Default=\\printserver\printserver-p27

For example..

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74465 - 2003-04-15 08:46 AM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure it errors [Big Grin]

your script is not current!
there is no such thing as $lpt1
_________________________
!

download KiXnet

Top
#74466 - 2003-04-15 08:56 AM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, newist one with old postprep engine (no tabs support [Frown] )



;Re-Write of http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=2;t=004308 By lonkero & kdyer
;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'
$ptr=$reg+'\Windows'
$nptr=READVALUE($ptr,'Device')
$lpt=split($nptr,',')[0]
$sysdrv=SUBSTR('%WINDIR%',1,2)
dim $priReg$x$i$rc$ps

IF EXIST('H:')
 $ps='H:\Scripts_DO_NOT_DELETE'
ELSE
 $ps=$sysdrv+'\Scripts'
ENDIF
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($nptr,'\\')
  ;WRITE THE DEFAULT PRINTER TO THE CONFIG
  $rc=WRITEPROFILESTRING($ps,'Printers','Default',$lpt)
  USE LPT1: /delete /persistent
  USE LPT1: $lpt /persistent
 CASE
  $nptr='' 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
  $lpt=READPROFILESTRING($ps,'Printers','Default')
  $rc=SETDEFAULTPRINTER($lpt)
  USE LPT1: $lpt /persistent
 CASE
  ;LOCAL PRINTER DEFAULT, SO WE WANT TO REMOVE ANY NETWORK MAPPING
  NOT INSTR($nptr,'\\')
  USE LPT1: /delete /persistent
ENDSELECT

_________________________
!

download KiXnet

Top
#74467 - 2003-04-15 09:35 AM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and with some cracking of engine we get it cleaner:


; 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
 
IF EXIST('H:')
$ps='H:\Scripts_DO_NOT_DELETE'
ELSE
$ps=$sysdrv+'\Scripts'
ENDIF
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($nptr,'\\') ;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



[ 15. April 2003, 09:46: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#74468 - 2003-04-16 09:08 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Correction..

Found:
code:
 CASE	INSTR($nptr,'\\')	;WRITE THE DEFAULT PRINTER TO THE CONFIG

Changed it to:
code:
 CASE	INSTR($nprt,'\\')	;WRITE THE DEFAULT PRINTER TO THE CONFIG

Updated the FAQ as well.

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74469 - 2003-04-16 09:13 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
damn, have something weird going with my eyes! [Eek!]

gladly you found it.
_________________________
!

download KiXnet

Top
#74470 - 2003-04-16 10:27 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Switched my local printer to be the default.. Removed all printers (local and net). Could not find the default anymore.. Could not write it either. [Frown]

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74471 - 2003-04-16 10:45 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh, have to check it out myself...
_________________________
!

download KiXnet

Top
#74472 - 2003-04-18 02:46 PM Re: Re-Write of "Default Printer" FAQ
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
So...

Are there any other takers of this? Or, do you use Roaming Profiles and the server does all of this for you?

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#74473 - 2003-04-18 03:16 PM Re: Re-Write of "Default Printer" FAQ
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh, the problem you got.
you made a default printer to be a LPT printer and then you wonder why the script does not make any net-printer the default?

not sure do I follow...

any other problems with this?
_________________________
!

download KiXnet

Top
Page 2 of 3 <123>


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

Who's Online
0 registered and 202 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.14 seconds in which 0.095 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