Error 2 when trying to use SetDefaultPrinter function

When trying to set a default printer using the SetDefaultPrinter function in KiXtart, error 2, "The system cannot find the file specified." is returned. This problem may be caused by using a share name instead of a printer name. This problem is made worse by confusing documentation.

The KiXtart documentation on SetDefaultPrinter says:

Note that if the printer involved was connected to using AddPrinterConnection, you must include both the servername and the printer name.

The example that follows in the documentation then shows the same \\servername\printername format being used for both the AddPrinterConnection and the SetDefaultPrinter calls.

The AddPrinterConnection actually uses the printer share name to connect to a network printer, however the SetDefaultPrinter function uses the printer name. If a network printer has a different share name than printer name, SetDefaultPrinter must be called using an (invalid) "UNC" path \\servername\printername.

Example:
For a printer named "HP LaserJet 4" shared from print server "SERVER" and shared as "HPLJ4" these functions should be called as follows:

If AddPrinterConnection ("\\SERVER\HPJL4") = 0
   ? "Added printer connection...."
   If SetDefaultPrinter ("\\SERVER\HP LaserJet 4") = 0
      ? "Set default printer to HP LaserJet 4...."
   Endif
Endif

Author: ASAK
Created: Oct 24 2005 (last modified Nov 28 2005)
Categories: KiXtart
TechByte #66

Warning: By visiting this site and/or by using any information contained herein, you agree to the Techbytes.ca terms of use.



Add a comment about this TechByte

If you wish to add a comment regarding this TechByte, please use the form below. Please note that by submitting comments using this form you are allowing all of the information submitted to be visible on this website. Any comments submitted using this form will only be shown on the website if they are approved by the administrators of this site. IF APPROVED, COMMENTS MAY TAKE SEVERAL DAYS TO BE POSTED.

Posted By: (Optional)

Comments:


Other TechBytes: