Reputation: 6259
I have developed a windows service with C#. Now I am searching a way, that it can print a specific file (could be a TIFF, PDF, HTML, MHT or Text) to a specific printer. The problem is, when I do it with a Process and print as verb, how can I set the specific printer? And is the way with using a Process also possible in a Windows Service? - It shouldn't show a window.
Upvotes: 1
Views: 5498
Reputation: 1
there is security around how printing can be handled via a service. if you you are running under a windows account then that service can printer with no UI. I have a print service on a server with a dedicated user account it is printing 1000 of files a day. to over 80 different networked printers.
your service must do and have the following:
Upvotes: 0
Reputation: 3708
Be aware that printing a PDF unattended violates the Adobe EULA in case of a PDF. Assuming that the .pdf extension is associated with the Adobe PDF Reader (or printer in this scenario...).
Upvotes: 0
Reputation: 612794
This proposed approach is likely to fail in my view. Using the shell verbs to print is going to invoke the associated applications to perform the printing. For many of these file types, this will result in UI being displayed which will fail in a service.
All the file types you mention can be printed direct from your service without recourse to other applications. It will require more coding but I believe it is the most viable solution for a service.
Alternatively you could do this from a standard app running on an interactive desktop. That should work fine and I presume you will be in control of the hardware and software configuration of the machines that run this code. Otherwise using shell verbs would be a terribly fragile and brittle approach-who knows what file associations are in place on a random customer's machine?!
Upvotes: 3
Reputation: 8427
the "Printto" verb needs an argument for the printer name. See this sample in MSDN for more details.
Upvotes: 2