1

My application started as a windows service which does not see printer installed on my PC.
But if this application is started as a regular windows application it can see this printer.
How can I install this printer, which should be accessible from windows service?

I need to send pdf files to this printer from a windows service. But windows service does not see my printer.
Windows service uses a Win API function EnumPrinters to get the list of printers.
Also, Win API function GetDefaultPrinter does not return default printer if this function is called from a windows service.

OS - Windows 7.
Printer - HP LaserJet P2055.
It is installed as network printer on a remote computer.
I install it on my PC using following steps:
1. Open Device and Printers.
2. Add a printer.
3. Add a network printer.
4. Find printer in the directory, based on location or feature.

  • This question is vague and lacks specific details for someone to be able to answer. Please provide more details on what version of Windows, brand & model of printer, what exactly you are try to accomplish and what you you've researched, etc. Details are very helpful. – CharlieRB Apr 4 '14 at 11:17
  • @CharlieRB Added some details. – Volodymyr Bezuglyy Apr 4 '14 at 11:40
0

You're probably running the service in different user context than when run interactively (as a 'normal app'). Try to run it in the context of a user who has a printer installed:

A Windows service that is designed to print can use the Win32 GDI APIs to print documents to a printer. There are some considerations when printing from Windows services, however. 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 call LogonUser(), LoadUserProfile(), and ImpersonateLoggedOnUser() before printing.

(quoted from: http://blogs.msdn.com/b/dsui_team/archive/2013/06/24/printing-from-a-windows-service.aspx)

You may also want to install your printer computer wide (for all users) using printui.dll, eg,:
Add per machine printer connection: rundll32 printui.dll PrintUIEntry /ga /n\\client2\printer2

(run rundll32 printui.dll,PrintUIEntry /? to see all options)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.