Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

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

share|improve this answer
    
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. –  Mohammadreza Sep 15 '09 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. –  John Gardeniers Sep 30 '09 at 11:14

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.

share|improve this answer
    
This is probably the most robust solution as the print jobs can queue locally if there is a network problem. –  Tony Edgecombe Dec 20 '09 at 10:12
up vote 0 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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