BMM
(Lurker)
2005-09-28 11:39 PM
SetDefaultPrinter() Overrides User Set Default Printer

Hi,
I created script that automatically connects our users to our network printer and sets a default printer in the process. Problem is when users set their own default printers, the process changes the default back to whatever is in the script when they relogin.

Is there anyway to make kixtart not set a default printer if the user has manually set another default printer (such as a local printer)?

Thanks.

Brian


LonkeroAdministrator
(KiX Master Guru)
2005-09-28 11:45 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

well, you need to know when the user has set the printer and when it's set by the script.

once you have that figured out, you can script it easily.


NTDOCAdministrator
(KiX Master)
2005-09-28 11:59 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

AddPrinterConnection( )

should not be setting a default printer. That would be done with

SetDefaultPrinter( )

If you want to remove a printer that is done with

DelPrinterConnection( )


There are also a few Printer related UDFs if needed as well. Look on one of the UDF sites for a sorted list.

http://www.kixhelp.com/udfs


BMM
(Lurker)
2005-09-29 12:07 AM
Re: SetDefaultPrinter() Overrides User Set Default Printer

Thanks, I am aware of those three functions. I am trying to find out if there is an easy way that someone had already worked out to determine if a user had local printers set as default before the script changed it to the network printer.

LonkeroAdministrator
(KiX Master Guru)
2005-09-29 12:14 AM
Re: SetDefaultPrinter() Overrides User Set Default Printer

think what doc ment that if you just add printers, the current default printer will be default.

anyways, what you need is a script that queries the current default printer.
and such script can be found in the udf library.


NTDOCAdministrator
(KiX Master)
2005-09-29 01:39 AM
Re: SetDefaultPrinter() Overrides User Set Default Printer

oh! You mean like this one?

GetDefaultPrinter() - Returns default printer
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=117544


NTDOCAdministrator
(KiX Master)
2005-09-29 07:53 AM
Re: SetDefaultPrinter() Overrides User Set Default Printer

And this UDF will allow you to log all the printers installed on the system if wanted.

EnumPrinterConnections2() - Enumerates all connected printers
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=137527


Les
(KiX Master)
2005-09-29 03:10 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

Just one question... How can a script tell if a user selected a default vs. the system picked the default? I mean, you ALWAYS have a default whether you choose or the system chooses for you.

LonkeroAdministrator
(KiX Master Guru)
2005-09-29 03:29 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

that's why I said that all you need to know is when it's set by user.
rest is just downhill


Les
(KiX Master)
2005-09-29 03:50 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

I know what you said Jooel, but you speak on such an esoteric level that one needs the delonkenizer 2.0 to decode.

LonkeroAdministrator
(KiX Master Guru)
2005-09-29 04:00 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

right...
hmm. I thought the latest release was 1.7.4.23


Les
(KiX Master)
2005-09-29 04:20 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

Right again... 2.0 is vapourware

tjcarst
(Hey THIS is FUN)
2005-09-29 04:44 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

BMM - I found this code on the boards. I don't actually use it to set my printers, I rem out the last lines so that I only record the current printers, but this looks like it might work for your needs. If there is a local printer set as default, it doesn't change to the network printer. You can populate the PrintSetup.ini with the printers you wish to add if there are none currently set.

Code:

;********** Default Printer Configuration
;This is to capture the Default Printer and get all network defined printers as well

$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=('\\server\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 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



LonkeroAdministrator
(KiX Master Guru)
2005-09-29 04:50 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

looks familiar...

tjcarst
(Hey THIS is FUN)
2005-09-29 06:09 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

Yes, as I noted I found it on the boards here. The original links no longer work. Here they are:

;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

* Edited to add a couple more that don't work, but were saved with script:
; 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


LonkeroAdministrator
(KiX Master Guru)
2005-09-29 06:18 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

is either one supposed to work?

tjcarst
(Hey THIS is FUN)
2005-09-29 06:30 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

Well, I must've believed they worked when I copied them into my script.

It doesn't really matter if they work, I guess. I posted the script I found and partially use and was just indicating that it wasn't my script, but rather gathered from the boards. It is a nice nod to someone else if you can give them credit for their code and for helping those of us who are kix-challenged. Too bad I don't have working links....


LonkeroAdministrator
(KiX Master Guru)
2005-09-29 07:00 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

hmmm...
there is the one version by MCA in the FAQ:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB10&Number=81655


tjcarst
(Hey THIS is FUN)
2005-09-29 07:53 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

I haven't seen that one before. Maybe that will work for BMM.

LonkeroAdministrator
(KiX Master Guru)
2005-09-29 08:01 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

actually, not so much of an FAQ as an function introduction post.

the wanted UDF getdefaultPrinter is in the udf library collection.

and shorter version:
http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=117544


tjcarst
(Hey THIS is FUN)
2005-09-29 08:26 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

I use getdefaultprinter.udf in my user login script. I record the printer to a file on a server so that I can look up the default printer for computers if needed. This way if someone new signs onto a computer and wants a printer installed or if the printer is deleted, I know which one to install. I use this mainly for reference.

For shared computers, I use different scripts to add and set default printers using Active Directory groups of some workstations for specific printers. I don't use this for computers that have only one user.


LonkeroAdministrator
(KiX Master Guru)
2005-09-29 08:38 PM
Re: SetDefaultPrinter() Overrides User Set Default Printer

eh, I thought you said setdefaultprinter overrides the old one?
it still does that.

now, on the next logon your getdefaultprinter would save the one set by your script as the default.

I think you should just simply do:
if not getdefaultprinter ;there is no defaultPrinter yet
setdefaultprinter("\\serverDude\everyonesDefault")
endif


tjcarst
(Hey THIS is FUN)
2005-09-30 01:54 AM
Re: SetDefaultPrinter() Overrides User Set Default Printer

I write the results of default printer to a logfile that includes the date/time, username, and default printer EACH time a user logs into the computer. This isn't really necessary, so it will probably be disabled. I set this up when I was going to migrate from one print server to another (novell to ms).

Now that I've setup the AD computer printer groups, it is simple to add printers to a workstation. The user calls complaining they can't print, I add their computer to appropriate computer group and have them login again. It works very slick for me.


tjcarst
(Hey THIS is FUN)
2005-09-30 01:59 AM
Re: SetDefaultPrinter() Overrides User Set Default Printer

I personally don't care if the default printer gets overridden. The users can print where I set them up to print. If they don't like it, they'll call and I can put their workstations in the appropriate default printer group and additional printer groups and they'll be happy. Default printers don't change much unless a new printer is added. The majority of my computers are shared by 20+ nurses or therapists. They print to the closest printer. If they need color, it is an additional printer and they know how to change it. New computers added to the network are put into the same printer groups as the rest of the surrounding computers. Computers that are not shared, do not usually get printers assigned via kixtart and printer groups.