Page 1 of 3 123>
Topic Options
#42117 - 2003-06-27 12:28 AM Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
Here is my entire test script:

AddPrinterConnection ("\\FILE\SALES_R1045")
AddPrinterConnection ("\\FILE\SALES_FAX")
SetDefaultPrinter ("SALES_R1045")

Now this should add two printers and set one of them as default. WindowsXP.

The problem is the default isn't setting itself and I get a return code of "2". Here's the odd part. If I add:
SetDefaultPrinter ("\\FILE\SALES_R1045")

right above my initial SetDefaultPrinter and run the script then it still doesn't work. Run the script a second and it works!

Remove that line and it doesn't matter how many times I run the script it wont set the printer as default.

Ideas?

Top
#42118 - 2003-06-27 12:36 AM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
This is even odder. Since it had to run twice I wanted to see what would happen if I plugged in that extra line twice:

AddPrinterConnection ("\\FILE\SALES_R1045")
AddPrinterConnection ("\\FILE\SALES_FAX")
SetDefaultPrinter ("\\FILE\SALES_R1045")
SetDefaultPrinter ("SALES_R1045")
SetDefaultPrinter ("\\FILE\SALES_R1045")

This sets the printer as default by only running the script once however there is a very bad after effect. When you go into printers the orignal printer is marked as default AND the new printer is marked as default. While other programs see the new printer as default (first selected) if you try to make another printer default (manualy) it fails.

Top
#42119 - 2003-06-27 02:38 AM Re: Problem With SetDefaultPrinter
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
You can display error codes with this line
code:
? 'Error '+@ERROR+' - '+@SERROR

Secondly, ADDPRINTERCONNECTION requires the share name of the printer whereeas SETDEFAULTPRINTER requires the printer name, they might not be the same.

Finally, if the user cannot install printer drivers, the ADDPRINTERCONNECTION might fail, too.
_________________________
There are two types of vessels, submarines and targets.

Top
#42120 - 2003-06-27 06:55 PM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
I've used that bit of code to determine what was wrong. Nothing gets displayed. As well the printer still is not set as default.

I've done this while booting the machine as well.

I am the administrator of my machine and the entire network. The printers get add just fine.

Top
#42121 - 2003-06-27 07:02 PM Re: Problem With SetDefaultPrinter
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Did you use the correct names? sharename/printername?
_________________________
There are two types of vessels, submarines and targets.

Top
#42122 - 2003-06-27 07:26 PM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
Yup, and to prove it and to test W2K I loaded a W2K station and logged on with that. Worked just fine.

So W2K works and XP doesn't.

Top
#42123 - 2003-06-27 07:47 PM Re: Problem With SetDefaultPrinter
Kdyer Offline
KiX Supporter
*****

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

Have you had a look at -

KiXtart FAQ & How to's

And specifically -
Default Printer Configuration

??

This has the SETDEFAULTPRINTER used within and we have several XP Workstations that works just fine.

Can I ask a silly question?

With the example you provided -
code:
AddPrinterConnection ("\\FILE\SALES_R1045")
AddPrinterConnection ("\\FILE\SALES_FAX")
SetDefaultPrinter ("\\FILE\SALES_R1045")
SetDefaultPrinter ("SALES_R1045")
SetDefaultPrinter ("\\FILE\SALES_R1045")

Why are you repeating the SetDefaultPrinter ?

Thanks,

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

Top
#42124 - 2003-06-27 07:52 PM Re: Problem With SetDefaultPrinter
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There are other issues with XP that may be at play here. Are you sure the script is even running on XP?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#42125 - 2003-06-27 08:34 PM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
"Why are you repeating the SetDefaultPrinter ?"
That was explained in the first two posts. Read them together and you have your answer.

"Are you sure the script is even running on XP?"
As I said above the printers get added just fine. I would have to say then the script is firing.

Top
#42126 - 2003-06-27 08:37 PM Re: Problem With SetDefaultPrinter
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well, you did say...
quote:
So W2K works and XP doesn't.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#42127 - 2003-06-27 09:15 PM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
Clarification:

Windows 2000 - Add Printers OK
Windows 2000 - Change Default OK

Windows XP - Add Printers OK
Windows XP - Change Default BAD

I reloaded the machine with W2K on it with WinXP and ran the script localy (no network setup). It worked fine. So either there is a problem running it remotly or there is a problem with my network setup conflicting with KiXtart.

Top
#42128 - 2003-06-27 09:59 PM Re: Problem With SetDefaultPrinter
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
quote:
I've used that bit of code to determine what was wrong. Nothing gets displayed.
what bit of code?
if you ment the line jens showed, there is something else wrong.
please verify.

the doubling of the lines are not needed.
just remove your initial line and leave the added "\\servername\printername"
_________________________
!

download KiXnet

Top
#42129 - 2003-06-27 10:33 PM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
ok, no offense to you but you need to re-read this post. I've already gone over that and I have explained twice why it's doubled up. Either way those extra lines are no longer in the the script, it was a TEST.

What I do see when I run the script as such:
AddPrinterConnection ("\\FILE\SALES_R1045")
AddPrinterConnection ("\\FILE\SALES_FAX")
SetDefaultPrinter ("SALES_R1045")

is "002".
When I add "? 'Error '+@ERROR+' - '+@SERROR", I get nothing else. Keep in mind it DOES add the printers.

Top
#42130 - 2003-06-27 10:38 PM Re: Problem With SetDefaultPrinter
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I keep in mind that I explained what you should do. [Big Grin]
small quote from manual:
quote:
SetDefaultPrinter( )

Action: Sets the default printer to which applications send print jobs.

Syntax: SETDEFAULTPRINTER ("printer name")

Parameters: Printer name
String that specifies the fully qualified name of the printer to set as the default printer. Note that if the printer involved was connected to using AddPrinterConnection, you must include both the servername and the sharename.

so, what is the part that you have explained?
told you to keep the extra line and remove your initial line.
just like manual says.
_________________________
!

download KiXnet

Top
#42131 - 2003-06-27 10:40 PM Re: Problem With SetDefaultPrinter
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Wouldn't it be -

SetDefaultPrinter ("\\FILE\SALES_R1045")

??

Thanks!

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

Top
#42132 - 2003-06-27 10:43 PM Re: Problem With SetDefaultPrinter
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes kent!
you said the words I couldn't.
that is the line he first added and removed and that is the line he MUST have there for it to work properly.
_________________________
!

download KiXnet

Top
#42133 - 2003-06-27 10:56 PM Re: Problem With SetDefaultPrinter
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Please also read the FAQ Forum under Why does the console display zeros and ones (amongst others)? .

Also
code:
? 'Error '+@ERROR+' - '+@SERROR

should display soemthing, at least a
code:
Error 0 - Function completed successfully

If it doesn't then there's something else wrong in your script, too.
_________________________
There are two types of vessels, submarines and targets.

Top
#42134 - 2003-06-27 11:15 PM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
No you are wrong, the following is incorrect:

SetDefaultPrinter ("\\FILE\SALES_R1045")

The following is my script:
AddPrinterConnection ("\\FILE\SALES_R1045")
AddPrinterConnection ("\\FILE\SALES_FAX")
SetDefaultPrinter ("SALES_R1045")

This works in W2K. So my SetDefaultPrinter statement is correct. Yours is wrong. It doesn't work in WinXP. HOWEVER the two lines above it does work. So my script is working.

You tell me to change the line but it works in W2K. You tell me my script doesn't work in general but it is adding the printers. As for that line of code once I see the "002" the window flashes by so quick and goes away maybe I'm just not seeing the return on it.

I guess this problem is above you. Never mind then. Thanks for your time.

Top
#42135 - 2003-06-27 11:30 PM Re: Problem With SetDefaultPrinter
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
If your code
code:
AddPrinterConnection ("\\FILE\SALES_R1045")
AddPrinterConnection ("\\FILE\SALES_FAX")
SetDefaultPrinter ("SALES_R1045")

produces an output of 002 then it means that the two ADDPRINTERCONNECTION functions have a return code of 0 (The function completed successfully) whereas the SETDEFAULTPRINTER has a return code of 2 (Error 2 - The system cannot find the file specified), which in your case would mean the printer.
If you run
code:
$rc=AddPrinterConnection('\\FILE\SALES_R1045')
? 'Error '+@ERROR+' - '+@SERROR
$rc=AddPrinterConnection('\\FILE\SALES_FAX')
? 'Error '+@ERROR+' - '+@SERROR
$rc=SetDefaultPrinter('SALES_R1045')
? 'Error '+@ERROR+' - '+@SERROR
? 'Press any key to continue'
get $keypress

you will se console output. The script will only progress once you hit a key. If you do not see any console output then it might be possible that your script is not running at all. So, please take a step back, and try it again, using the script EXACTLY as I posted it.

And remember, we are all volunteers here, that are trying to help you!
_________________________
There are two types of vessels, submarines and targets.

Top
#42136 - 2003-06-27 11:42 PM Re: Problem With SetDefaultPrinter
Justin Emlay Offline
Fresh Scripter

Registered: 2002-05-24
Posts: 26
Ok, lets take it from here then.

I did as such and again I got 002. Only on seperate lines with the verbage you specified. The 2 meaning can not find file specified.

So now answer this. If SetDefaultPrinter can not find file specified then how can SETDEFAULTPRINTER find it and install it.

Also when I move to a W2K machine I get "000" and it works fine.

Also, I HAVE tried to just use "SetDefaultPrinter ("\\FILE\SALES_R1045")" and that doesn't work either. I get a "000" but it doesn't actualy set the printer as default. Also that doesn't explain how this:
"SetDefaultPrinter ("SALES_R1045")"
does work just fine for W2K.

Are you tring to tell me that W2K requires it one way and WinXP requires it the other way?

Cut and paste:
Error 0 - The operation completed successfully.
Error 0 - The operation completed successfully.
Error 2 - The system cannot find the file specified.
Press any key to continue

Top
Page 1 of 3 123>


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

Who's Online
0 registered and 366 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.074 seconds in which 0.025 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