3

I have a Windows Service application that every now and then should print some documents. As far as I know, to print those documents, my service must be run with a user account other than Local Service or Network Service. So i have created a user account and added that to the Administrators group and ran the service with it.

With locally installed printers, I don't have any problems because those printers are automatically installed for all accounts. To be able to print with the network printers, I have created another application that syncs the installed printers of the currently logged in user with the user account that my service uses with the rundll32.exe printui.dll,PrintUIEntry command.

In Vista and Windows7 I don't have any problems with the syncing of the printers because every time that a printer should be installed the authentication window will open and it asks for the appropriate user account to install that printer (The service user account is not created on the network printers computers) but in XP a find dialog with the "Connecting to {printername}" caption will appear and stops responding, or sometimes it installs the printer but every time service tries to print, a Win32Exception with "A StartDocPrinter call was not issued" message will throw and in the user account that runs the sync application a duplicate printer will be shown and I couldn't delete those printers unless with force (using registry).

Am I doing the right thing for printing documents with Windows Services at all? If yes, how can I solve the above-mentioned problem? And if not, what the heck should I do?

Thanks.

4 Answers 4

1

You can log on to the computer as your service user accounts and add/configure/test network printers manually.

2
  • 1
    There is nothing wrong the user account. I have tested it the way you mentioned. But I don't want to log in to the account every time a printer installed or removed. This is why i have developed the sync application.
    – mrtaikandi
    Sep 15, 2009 at 14:35
  • How often do you install or remove printers that will be used for this service? Massimo's answer is the way I have always done it because it's fool proof. Sep 30, 2009 at 11:14
1

Why not set all printers up with a local queue, that way they're always local printers and you don't have the issue?

You can point a local queue to a network printer by creating a local port with the relevant IP address of the printer. (Go through the Add Printer wizard, Add a Local Printer (don't let it search plug and play), Create a New Port, Use Standard TCP/IP port.

1
  • This is probably the most robust solution as the print jobs can queue locally if there is a network problem. Dec 20, 2009 at 10:12
0

I have solved the problem by requesting a network authentication to the server first and then installing the printer.

Thank you guys for your help.

0

I think you may be doing unnecessary work here. If you install the printers with a so-called "per-machine connection", then the printer will be available to all users and services on that machine. I know we print from Tomcat running as a service this way. Caveat: I am not 100% sure this works for the Local Service account.

Sounds like you already know about PrintUI.dll PrintUI.DLL User’s Guide and Reference

The salient parts:
    rundll32 printui.dll PrintUIEntry /in /n\machine\printer
-or-
    rundll32 printui.dll PrintUIEntry /if /f %windir%\inf\ntprint.inf /r "lpt1:" /m "HP PSC 500"

Doing it the way you describe may create an unnecessary weakening of your security. Services should run with the minimum permissions required to get their jobs done. When you run them in a user account, you can easily inadvertently give your service privileges it shouldn't have.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .