Printing in a Windows Service
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, A开发者_StackOverflowlexander
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
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)
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
精彩评论