Justin Emlay
(Fresh Scripter)
2003-06-27 12:28 AM
Problem With SetDefaultPrinter

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?


Justin Emlay
(Fresh Scripter)
2003-06-27 12:36 AM
Re: Problem With SetDefaultPrinter

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.


Sealeopard
(KiX Master)
2003-06-27 02:38 AM
Re: Problem With SetDefaultPrinter

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.


Justin Emlay
(Fresh Scripter)
2003-06-27 06:55 PM
Re: Problem With SetDefaultPrinter

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.


Sealeopard
(KiX Master)
2003-06-27 07:02 PM
Re: Problem With SetDefaultPrinter

Did you use the correct names? sharename/printername?

Justin Emlay
(Fresh Scripter)
2003-06-27 07:26 PM
Re: Problem With SetDefaultPrinter

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.


Kdyer
(KiX Supporter)
2003-06-27 07:47 PM
Re: Problem With SetDefaultPrinter

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


Les
(KiX Master)
2003-06-27 07:52 PM
Re: Problem With SetDefaultPrinter

There are other issues with XP that may be at play here. Are you sure the script is even running on XP?

Justin Emlay
(Fresh Scripter)
2003-06-27 08:34 PM
Re: Problem With SetDefaultPrinter

"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.


Les
(KiX Master)
2003-06-27 08:37 PM
Re: Problem With SetDefaultPrinter

Well, you did say...
quote:
So W2K works and XP doesn't.


Justin Emlay
(Fresh Scripter)
2003-06-27 09:15 PM
Re: Problem With SetDefaultPrinter

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.


LonkeroAdministrator
(KiX Master Guru)
2003-06-27 09:59 PM
Re: Problem With SetDefaultPrinter

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"


Justin Emlay
(Fresh Scripter)
2003-06-27 10:33 PM
Re: Problem With SetDefaultPrinter

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.


LonkeroAdministrator
(KiX Master Guru)
2003-06-27 10:38 PM
Re: Problem With SetDefaultPrinter

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.


Kdyer
(KiX Supporter)
2003-06-27 10:40 PM
Re: Problem With SetDefaultPrinter

Wouldn't it be -

SetDefaultPrinter ("\\FILE\SALES_R1045")

??

Thanks!

Kent


LonkeroAdministrator
(KiX Master Guru)
2003-06-27 10:43 PM
Re: Problem With SetDefaultPrinter

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.


Sealeopard
(KiX Master)
2003-06-27 10:56 PM
Re: Problem With SetDefaultPrinter

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.


Justin Emlay
(Fresh Scripter)
2003-06-27 11:15 PM
Re: Problem With SetDefaultPrinter

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.


Sealeopard
(KiX Master)
2003-06-27 11:30 PM
Re: Problem With SetDefaultPrinter

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!


Justin Emlay
(Fresh Scripter)
2003-06-27 11:42 PM
Re: Problem With SetDefaultPrinter

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


LonkeroAdministrator
(KiX Master Guru)
2003-06-27 11:42 PM
Re: Problem With SetDefaultPrinter

justin, ok.
sure you can say that the software author is wrong and does not know how his software works.

as you, I would twice think before making such statement.
that says directly something about you.


Justin Emlay
(Fresh Scripter)
2003-06-27 11:49 PM
Re: Problem With SetDefaultPrinter

I'm purly being logical.

For me this works in W2K:
SetDefaultPrinter ("SALES_R1045")

For me, it doesn't work in WinXP and I've proven my script is running and so far only I've given input as to why it works for one OS and not the other. I'd heard nothing from anyone else. I've gotten two people telling me two different things. The manual states to use the printer NAME and not the printer PATH

Printer NAME - SALES_R1045
Printer PATH - \\FILE\SALES_R1045

So if someone tells me to use the printer PATH when the manual tells me to use the printer NAME and using the printer NAME actualy works then someone is wrong. Or the manual is wrong and I'm imagining things on my W2K terminal.

Take your pick.


LonkeroAdministrator
(KiX Master Guru)
2003-06-27 11:52 PM
Re: Problem With SetDefaultPrinter

I don't know what you have read.
I took a quote from manual which states what the parameter should be.

it says you MUST use the proper way.
that is what it says to me.

wonder if we are reading different manual...


Sealeopard
(KiX Master)
2003-06-27 11:54 PM
Re: Problem With SetDefaultPrinter

Can you manually set that particular printer as default printer under Windows XP? Can you manually connect to that particular printer wiht Windows XP? Have you printed a test page? Are there any entries in the eventlog?

Please remove all printers before attempting to reconnect.


Justin Emlay
(Fresh Scripter)
2003-06-28 12:09 AM
Re: Problem With SetDefaultPrinter

Lonkero,
You are being insulting and you are not helping. I did not know anyone here was the author of anything. How could I and why should I? I am not responding to you anymore. Sealeopard is the only one here actually helping.

Sealeopard,
I removed all printers then added one myself. I have to have something to switch from or else one of the newly created printers could become default simply because it was the first created. I shut down the machine completely. Booted the machine. Logged onto the machine and saw the usual in the window, "000". Both printers where added and the old printer remains the default. There is nothing in the log.

I used as you suggested:
AddPrinterConnection ("\\FILE\SALES_R1045")
AddPrinterConnection ("\\FILE\SALES_FAX")
SetDefaultPrinter ("\\FILE\SALES_R1045")

I'm going to drop that fact that this works in W2K:
SetDefaultPrinter ("SALES_R1045")
And simply consider it a coincidence.


Justin Emlay
(Fresh Scripter)
2003-06-28 12:11 AM
Re: Problem With SetDefaultPrinter

I forgot the following:

"Can you manually set that particular printer as default printer under Windows XP?"
Yes I can install them and set which ever I want as default.


LonkeroAdministrator
(KiX Master Guru)
2003-06-28 12:27 AM
Re: Problem With SetDefaultPrinter

thanks for the feedback.
I try not to interfier the life of starter kixters anymore. [Eek!]


Kdyer
(KiX Supporter)
2003-06-28 04:19 AM
Re: Problem With SetDefaultPrinter

Justin,

With the FAQ link I referenced, we (the companies I work for) use it on a daily basis to write an INI file to the client's home drive. That is, if they login to another workstation, they get the printers and the default.

Again, we have several XP (or hopped up W2k) machines that this works perfectly with. And more specifically with the method(s) in question.

Thanks,

Kent


Justin Emlay
(Fresh Scripter)
2003-07-01 05:59 PM
Re: Problem With SetDefaultPrinter

Shooting in the dark...

Where your WinXP machines installed with Service Pack 1 integrated in to the installation files?

Thanks,
Justin


**DONOTDELETE**
(Lurker)
2003-07-11 03:28 PM
Re: Problem With SetDefaultPrinter

I also wish to map printers in a XP sp1 environment.

This works;
$rc=AddPrinterConnection('\\i1print2\i1t41179')
$rc=SetDefaultPrinter('\\i1print2\i1t41179')

This fails;
$rc=AddPrinterConnection('\\i1print2\i1t41179')
$rc=SetDefaultPrinter('i1t41179')

The 4.20 manual gives this example;
If AddPrinterConnection ("\\vleerbeer\hp laserjet 4") = 0
? "Added printer connection...."
If SetDefaultPrinter ("\\vleerbeer\hp laserjet 4") = 0
? "Set default printer to HP LaserJet 4...."
Endif
Endif

But the syntax is still SETDEFAULTPRINTER("printername")

Needs to be fixed in the manual!


Sealeopard
(KiX Master)
2003-07-11 03:38 PM
Re: Problem With SetDefaultPrinter

Question: Is the share name of the printer "SALES_R1045" identical to the printer name SALES_R1045". This is an important distinction. Additionally, when you look at your printer list, did you refresh the list after running the script?

I do have to agree with Jooel, that the error codes in Kixtrat are very reliable as they are received directly from the Windows API. Aslo, you are the only oen reporting this particular problem, which would indicate that it might rather be a problem with the computer you are testing it on. there at a lot of settings in windows XP, especially security settings wich can influence somethings seemingly as simple as adding printers or setting default printers.

You can always install Windows XP in an out-of-the-box configuration and retest your script. This woudl actually be a necessary step to show whether it's a script, Windows, or configuration problem.


Les
(KiX Master)
2003-07-11 04:03 PM
Re: Problem With SetDefaultPrinter

Mark K,
Don't take it too literally. The example shows the proper syntax.


LonkeroAdministrator
(KiX Master Guru)
2003-07-11 04:09 PM
Re: Problem With SetDefaultPrinter

indeed it seems that manual might have an error.
quote:

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.

but indeed the error is not as you suggested.
your error was that you didn't read the manual.

if there is error, it's about sharename part.
afaik, it should be "\\servername\printername" or ruud has changed something later on that it works this way.


**DONOTDELETE**
(Lurker)
2003-07-11 04:15 PM
Re: Problem With SetDefaultPrinter

Not sure how XP works for sure, but in 2000 the default printer can be set in the registry by using the following line:
code:
 WRITEVALUE ("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", "$NewDefPrnt", "REG_SZ") 

All you have to do is set the $NewDefPrnt value in your script. This was a line from a script I wrote to change printer settings after moving print queues to another server.


**DONOTDELETE**
(Lurker)
2003-07-11 05:20 PM
Re: Problem With SetDefaultPrinter

Lonkero

Ouch! I did read the manual, but it was the one that came when I downloaded 4.20. The version you have seems better - which one is it?

Mine sez:
ADDPRINTERCONNECTION
Action
Adds a connection to the specified printer for the current user.

Syntax
ADDPRINTERCONNECTION ("printer name")

Parameters
Printer name
The (share)name of the printer to which to connect.


Les
(KiX Master)
2003-07-11 05:25 PM
Re: Problem With SetDefaultPrinter

Mark K,
As I already mentioned, the example does offer more. Old manuals cannot be rewritten. They are frozen in time. If you want to make a suggestion for future versions, post it to the suggestions forum.


Sealeopard
(KiX Master)
2003-07-11 05:51 PM
Re: Problem With SetDefaultPrinter

You should also use the latest KiXtart version, which is v4.21, see 4.21 *final* is now available

[ 12. July 2003, 15:29: Message edited by: sealeopard ]


LonkeroAdministrator
(KiX Master Guru)
2003-07-11 06:40 PM
Re: Problem With SetDefaultPrinter

now was I rude or what? [Wink]
anyway, still your manual speaks about sharename as printername-parameter.

indeed old manual was more misleading than the current one.
I see no reason why the parameter should be titled as printername as that makes the confusion bigger than it needs to be.
simple reduction to "printer" would already reduce the risk of fatal error [Wink]

anyway, I was reading 4.21 manual...
didn't remember you saing anything about version so just assumed.
version 4.21 is available on other kixtart download locations but not on korg.
as example KiX2001_421.zip


Duckling
(Fresh Scripter)
2003-10-06 04:16 PM
Re: Problem With SetDefaultPrinter

Just to add my 2p:

I have exactly the same problem.
W2K works fine, XP does not. Running v4.20,
will try 4.21 tomorrow.
Printer name and printer share name is exactly the same.
I use the following code:

if InGroup("PRINTER501")
AddPrinterConnection("\\SERVERNAME\PRINTER501")
endif

if InGroup("SOMEDEPT")
SetDefaultPrinter("\\SERVERNAME\PRINTER501")
endif


Kdyer
(KiX Supporter)
2003-10-06 04:37 PM
Re: Problem With SetDefaultPrinter

Mr. Duckling - Can you start your own thread on this?

Co
(MM club member)
2003-10-07 08:05 AM
Re: Problem With SetDefaultPrinter

Justin,

It isn't really the answer to your question but maybe you can take a notice... [Frown]

I did a printserver migration and used a script ( See Topic) to change the servername at the clients

First the script removes the printers connected with the old server and after that it reconnect the same printers on the new server. The default printer didn't change by reconnection.

Try to add: [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows]
"Device"="\\\\printserver\\printername,winspool,Ne3:" (the one you want to be default printer)

If it doesn't work with user credentials try if it works with admin credentials. Maybe that is the problem... [Roll Eyes] [Roll Eyes]