Article ID: 152551 - View products that this article applies to.
This article was previously published under Q152551
Prior to Windows 95 and Windows NT, network print shares were used in Windows by connecting MS-DOS devices to network resources. Often, this was accomplished by the WNetAddConnection function that was implemented by the underlying network software. This architecture limited the number of connections to the number of MS-DOS devices that could be redirected. Further, it suffered from an inherent inflexibility of print job and printer management.
The current Win32 Application Programming Interface (API) defines a collection of functions known as the Print Spooler API. The Print Spooler API manipulates the Spooler, a component of the operating system that is always running, and manages printers and print jobs both local and remote. The Spooler and its printers are no longer tied to MS-DOS devices for access to network print shares. Any printer in Windows can now be connected (redirected) directly to network print shares by their UNC names.
Configuring a printer to be redirected to a network print share is a three- step process: The application first obtains a current PRINTER_INFO_2 structure via the GetPrinter function; the new configuration is then defined by altering the members of the PRINTER_INFO_2 structure; once modified, the structure is passed to the SetPrinter function that resets the configuration.
To configure a printer to print to a network print share, set the pPortName member of the PRINTER_INFO_2 structure to point to a valid port name string. Windows NT requires the name of the port to be in the list of ports that are returned from the EnumPorts function. On Windows 95, this string may contain the UNC path to a remote network print share or can be from this list of installed ports. Additional ports are defined by calling the AddPort function and specifying the appropriate Port Monitor.
When AddPort is used to set up a new port, a dialog box provided by the Port Monitor appears. There is no way to prevent this dialog box from being displayed. The Port Monitor uses this dialog box to configure the new port with information specific to that type of port.
Although Windows NT supports the redirection of local printers to network print shares, the recommended method for printing to a network print share on Windows NT is a Printer Connection. A Printer Connection is a direct representation of the network printer resource on the local workstation. Printing to a Connection involves Remote Procedure Calls (RPC) that offer many advantages, such as spooling on the Server and Server-supplied printer drivers. However, Printer Connections currently work only when the client and server are both Windows NT or if the network specifically supports it.
Microsoft recommends that applications running on Windows NT attempt to call AddPrinterConnection to define Network Printers to which applications would print. If AddPrinterConnection fails, applications should then attempt to use a local printer redirected to the network print share as this article describes. Use and diagnosis of AddPrinterConnection failures is beyond the scope of this article.
For more information on the use of AddPrinterConnection and how to install local printers, please see the following article in the Microsoft Knowledge Base:
147202Use the following steps to configure a printer with the Print Spooler functions:
(http://support.microsoft.com/kb/147202/EN-US/ )How to Add a Network Printer Connection
Sample CodeThe following code sample demonstrates the calls to GetPrinter and SetPrinter:
Article ID: 152551 - Last Review: November 21, 2006 - Revision: 2.2
Contact us for more help