PRB: Errors When Printing from ASP Pages or from Windows Services (324565)



The information in this article applies to:

  • Microsoft .NET Framework SDK 1.0
  • Microsoft Windows XP Professional
  • the operating system: Microsoft Windows XP 64-Bit Edition

This article was previously published under Q324565

SYMPTOMS

When you print from ASP pages or from Windows Services, no page is ejected, or other errors occur.

CAUSE

The use of the .NET Framework Printing classes is not supported from a service. This includes ASP pages, which generally run in the context of the server service.

RESOLUTION

Any service that is designed to print must directly use the Win32 APIs, instead of the .NET Framework Printing classes.

STATUS

This behavior is by design.

MORE INFORMATION

The use of the Printing classes is not supported from a service or ASP page. Therefore, if printing is required in this scenario, then a second service must be written, using only Win32 APIs. This service would then print at the request of the ASP page or .NET service. The request can be made by means of Interprocess Communication (IPC), such as a named pipe, event, shared section, or similar means.

The following are some cautions for printing from Win32 services:
  • If all the print jobs can be sent with one user's credentials, the service can be run under that user's account and will have access to the printers that are known to that user on that computer.
  • If the service must print using the credentials of one or more users defined at run time, then the service must LogonUser(), LoadUserProfile(), and ImpersonateLoggedOnUser() before printing. If the user has never logged on to the server computer before, the service must also AddPrinterConnection() as appropriate. This approach will leave residue behind in the form of printer connections, registry hives, per-user directories on the hard disk, and others.

Modification Type:MinorLast Reviewed:5/10/2006
Keywords:kbDSWGDI2003Swept kbprb KB324565 kbAudDeveloper