#148200 - 2005-09-21 03:08 PM
SetDefaultPrinter() - documentation error
|
reedmikel
Fresh Scripter

Registered: 2005-09-21
Posts: 27
|
I've spent over 10 hours trying to get a logon script that sets a workstation's default printer to function properly The workstations are all XP-SP2 machines connected to a Windows 2000 Advanced server. The printer is a server-based printer shared as \\servername\sharename. At first I tried using KIX's SHELL command to execute a rundll32 printui.dll,PrintUIEntry /y /in /n\\servername\sharename command. Notice the command was to add the network printer AND set it to be the default printer. But it would fail, reporting it could not find or connect to printer. After hours of playing around with printui.dll, I got the bright idea to check KiXtart, which my script was written in, and saw the AddPrinterConnection() and SetDefaultPrinter() commands Now the AddPrinterConnection("\\servername\sharename") command worked just as documented. BUT the SetDefaultPrinter("\\servername\sharename") would always return an error code 2(I think 2 means: not found). More time spent testing variations of my script, but still could not set the default printer...
Finally I searched this forum, and saw quite a few folks with similiar problems. Overwhelmingly the advice was to use the same name for sharename as for printer name. Well, us older legacy appl folks do not like to do that, preferring to keep sharenames to 8 or less characters, no spaces etc. Printer names, on the other hand, are supposed to be verbose and clearly identify the printer to the user. So in a last ditch effort at 12:30am last night(morning), I tried SetDefaultPrinter("\\servername\printer name"). Amazing - it worked 
So the reason for my post is twofold: 1) save others hours of wasted time 2) let the author(s) know that their documentation has been incorrect all these years for the SetDefaultPrinter() command
Below is the description from kix2001.doc - notice that it says to use "sharename". WRONG - please update it to say PRINTER NAME. And you might as well add a special note: (unlike AddPrinterConnection(), this command does NOT use the sharename, but the full name of printer).
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...
Don;t get me wrong, I LOVE KiXtart! Just don't like spending endless hours tracking down documentation errors. OTOH, I should have known better as I am a programmer. Years ago I wrote FoxPro code that called low-level Windows APIs and I think I encountered a similiar problem. If I remember correctly, the underlying OS made a difference. I think Win9x needed the \\servername\sharename, whereas NT,2000,XP etc. needed \\servername\printername. I'm guessing KiXtart uses the same Windows APIs and that is the reason for this confusion. Perhaps the documentation may need to be even further enhanced to explain that the syntax for SetDefaultPrinter is OS-dependent. But I leave that testing to someone else 
Thanks for such a great tool!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 555 anonymous users online.
|
|
|