1

I'm trying to print in a Windows Service. The following VB.Net code is used:

    Dim _pd As New System.Drawing.Printing.PrintDocument()

    AddHandler _pd.PrintPage, New System.Drawing.Printing.PrintPageEventHandler(AddressOf PrintDocument_PrintPage)
    AddHandler _pd.EndPrint, New System.Drawing.Printing.PrintEventHandler(AddressOf PrintDocument_EndPrint)

    _pd.Print()

The EventHandlers are implemented and tested. When I run the code (with AccountType: User) I'm getting an exception saying, that "no printer is installed". In a Windows Forms Application everything works.

I'm using a Network printer.

Thank you in advance, Alexander

alxppp
  • 107
  • 1
  • 10

3 Answers3

1

Try this code, it can make you print anything:

Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.FileName = sReport
Process.Start(psi)
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
AlMounkez
  • 67
  • 3
1

Printing in Windows Services is not recommended.

you need to use a different account for your service,( domain account) so that you can access network resources.

You can find more info at: Network printing with window service

Community
  • 1
  • 1
Kamyar
  • 18,639
  • 9
  • 97
  • 171
0

You can print via Windows service with the help of windows APIs. System.Drawing.Printing doesn't go well with service.

Check this link : http://support.microsoft.com/kb/322090

Sukhi
  • 13,261
  • 7
  • 36
  • 53