2

How can I printing a document on a specific printer from a Windows-Service without the need of any user-interaction?

A string, or a text-file. Maybe Crystalreport?

Thanks.

chriszero
  • 1,311
  • 3
  • 13
  • 26

5 Answers5

2

The point is not how to print from a windows service or from an application, if you don't want any user interaction to be required you have to specify all print parameters without any need to show a print dialog ( which you can't because a windows service has no access to the UI ).

see here: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • Unfortunately, printing from windows services is not recommended officially: [Discussion](http://stackoverflow.com/a/8094/1182448). – apdevelop Feb 08 '13 at 11:44
0

To 'silently' print from a Windows Service you should utilise Win32 GDI API.

If you are developing a Microsoft .NET application, you can use Platform Invocation Services (PInvoke) to call the Win32 GDI APIs to print. Heres a nice PInvoke tutorial. Take a look here for Win32 GDI methods etc.

Here is more information and an example regarding printing from a windows service from Microsoft's DSUI team... take a look

Paul Zahra
  • 9,522
  • 8
  • 54
  • 76
  • 1
    If someone comes here looking for the blog post on MSDN linked above, here is the updated link to it: https://learn.microsoft.com/en-us/archive/blogs/dsui_team/printing-from-a-windows-service – Santosh Mar 15 '22 at 14:38
0

Try to create a Multithreaded Services. Once you create the service with Admin previledges, it won't get interfere by users. (Actually I didn't understantpurpose of "without the need of any user-interaction")

PawanS
  • 7,033
  • 14
  • 43
  • 71
  • @david well, given he did admit that he doesn't understand that part of the question it's not unfair to say that his answer may not be correct. you're comment's a bit harsh. @pawan, i think the OP wants a method that will programatically and automatically print either via some event or other triggers that is not kicked off by the user. so whether the service is multithreaded or not is irrelevant in this case as david pointed out. – Joe Feb 09 '11 at 13:31
  • @David, ya I didn't understand the question, but I tried to give answer to my level best.Still I'm learning... Don't worry, thatx for criticising me. A day come when I'll answer better than u. @joe... thanku, next time I try to understand the question before answering. – PawanS Feb 10 '11 at 06:32
0

There is another discussion on this using crystal reports: Print without Printer selection dialog

And here's another one for printing html Print html document from Windows Service without print dialog

Hopefully, they'll get you started in the right direction.

Community
  • 1
  • 1
Joe
  • 11,147
  • 7
  • 49
  • 60
0
// Class that handles printing
class MyPrintDocument : PrintDocument
    {
       //...
    }

when you want to print:

        // Create an instance of your printer class
        MyPrintDocument printer = new MyPrintDocument();

        // Set StandardPrintController so status dialog won't appear
        printer.PrintController = new StandardPrintController();
Arie
  • 5,251
  • 2
  • 33
  • 54