alxppp
alxppp

Reputation: 107

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, Alexander

Upvotes: 1

Views: 3932

Answers (3)

AlMounkez
AlMounkez

Reputation: 77

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)

Upvotes: 1

Sukhi
Sukhi

Reputation: 14145

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

Upvotes: 0

Kamyar
Kamyar

Reputation: 18797

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

Upvotes: 1

Related Questions