Page 1 of 1 1
Topic Options
#168043 - 2006-09-19 04:29 AM Default Printer Problem
kuwahard Offline
Fresh Scripter

Registered: 2005-09-09
Posts: 8
Have kind of a strange problem or maybe not so strange is my hope to people on here

Here's part of the login script code I use to set my default printer for a computer lab. Both the name of the printer and the share/queue are the same name. Also the people using this lab only have User level rights.

OS: Windows XP SP2

Code:
  
if $Location = "Milne"
? "Mapping Milne Main Printers"
If AddPrinterConnection ("\\onid-print\scf_main") = 0
? "Added printer connection...."
Endif
If SetDefaultPrinter ("\\onid-print\scf_main") = 0
? "Set default printer to SCF Milne Main Printer"
Endif



Now this script works (as in sets the correct Default Printer) only about 20% of time on the first run. If I run the script several times in a row, then it works. However I would rather not run the script 10 times in a row just to get this setting to stick. I realize it is supposed to return an error code if it cannot find the printer?, however it does not return on, suggesting it is finding the printer. Does anybody have any suggestions on how to make the default printer stick on the first run and/or some way of testing to see if the default printer is set other then using this function.

Daniel.

Top
#168044 - 2006-09-19 06:07 AM Re: Default Printer Problem
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Does this happen mainly on the first logon after reboot? what's the error cdoe being returned from SETDEFAULTPRINTER()?
_________________________
There are two types of vessels, submarines and targets.

Top
#168045 - 2006-09-19 07:42 AM Re: Default Printer Problem
kuwahard Offline
Fresh Scripter

Registered: 2005-09-09
Posts: 8
I have to admit I haven't really paid attention to the reboot, so I'll look at that more closely.. As for error messages I get no errors in running the script, no codes, no messages. Also it's pretty random when it comes to when it decides to work or not work. For some users it works, for others it doesn't. All the users we get are identical when it comes to rights on the desktop.

Daniel.

Top
#168046 - 2006-09-19 09:51 AM Re: Default Printer Problem
RemcovC Offline
Starting to like KiXtart
*****

Registered: 2006-09-13
Posts: 174
Loc: Holland
The reason you get no error messages is because you filter them:
Code:

If AddPrinterConnection ("\\onid-print\scf_main") = 0
? "Added printer connection...."
Endif



If you change this to something like this:
Code:

If AddPrinterConnection ("\\onid-print\scf_main") = 0
? "Added printer connection...."
Else
? "Error number : " + @Error
? "Error message: " + @SError
Endif


It should return an error, on failure
_________________________
It's better to have scripted and died, then to never have scripted at all

Top
#168047 - 2006-09-19 06:40 PM Re: Default Printer Problem
kuwahard Offline
Fresh Scripter

Registered: 2005-09-09
Posts: 8
For the SetDefaultPrinter statement this is the error code I get:

"ERROR_FILE_NOT_FOUND 2 The system cannot find the file specified."

I double checked the printer name, share name, and queue name, they are all the same name. If I put a goto into that if else statement I can get it to set eventually, but it takes a minute or so which really isn't all that great. Although something interesting I noticed was the loop would finally break at the same time on each computer. Is there something that Windows is loading during login that allows the SetDefaultPrinter() function to finally work? I'm going to try to just put in a "sleep" into the script and see if that helps unless there is a better way.

Daniel.

Top
#168048 - 2006-09-19 06:53 PM Re: Default Printer Problem
kuwahard Offline
Fresh Scripter

Registered: 2005-09-09
Posts: 8
Put in a sleep delay of 40 secs fixed the problem. Would be nice if there was a better way to do this.

Daniel.

Top
#168049 - 2006-09-19 07:02 PM Re: Default Printer Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
do you run the script during login on have you tried it while logged on?
Top
#168050 - 2006-09-19 07:17 PM Re: Default Printer Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
I think the manual is wrong, it should be:

SetDefaultPrinter("{Printer Label Name}")

e.g: SetDefaultPrinter("Bro-HL1440")

Try this with the label name of the added printer, and let us know.

Top
#168051 - 2006-09-19 07:27 PM Re: Default Printer Problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you mean that the server name should be omitted from the line?
Top
#168052 - 2006-09-19 10:21 PM Re: Default Printer Problem
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Quote:

Printer Config
Printer Name: HP LaserJet 6L
Share Name: HPLaserJ
PC Name: richardpc




Code:
SetDefaultPrinter("\\richardpc\HPLaserJ")
? 'Error: '+@ERROR+': '+@SERROR


Quote:

Error: 2: The system cannot find the file specified.




Code:
SetDefaultPrinter("HPLaserJ")
? 'Error: '+@ERROR+': '+@SERROR


Quote:

{Error: 2: The system cannot find the file specified.




Code:
SetDefaultPrinter("HP LaserJet 6L")
? 'Error: '+@ERROR+': '+@SERROR


Quote:

Error: 0: The operation completed successfully.




As you can see the last code that uses the printer lable name works, tested using Windows XP SP2.

IIRC you need admin rights to set default printer under Windows XP SP2 as well, will report back but I think it has been reported in old posts.

Thanks

Rich

Top
#168053 - 2006-09-20 01:34 AM Re: Default Printer Problem
kuwahard Offline
Fresh Scripter

Registered: 2005-09-09
Posts: 8
I haven't had a chance to test out the change, the "sleep" wait I put in is working fine for now. Also you don't need Admin rights to set the default printer in XP SP2, our users with straight user level non-admin rights can assign a default printer manually.

Daniel.


Edited by kuwahard (2006-09-20 01:36 AM)

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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.178 seconds in which 0.084 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