views:

206

answers:

1

I have a C# windows service which is running under the NetworkService account. It occassionally needs to print a Chart object which I do by simply calling:

chart.Printing.Print(false); // suppress the Printer Dialog

The weird thing is it seems works fine running as a console application.

The only way it will work is if I run the service under a local admin account.

+2  A: 

You probably needed access granted for System.Drawing.Printing.PrintingPermission. Reading the documentation, you find the following:

Classes within the System.Drawing.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

RichardOD
Yeah the weird thing is it doesn't throw an exception it just ignores the call, which would come under *unexpected problems*. How would I grant access to the PrintingPermission class? Do I just give NetworkService access to the specific folder the assembly is in?
James
It's odd that you don't get an error with printing.
RichardOD
@James- have you also considered creating a low privilidge service account to run the code under?
RichardOD
@Richard just tried it out there, created a new user with the basic User template permissions. Didn't work. There must be a permission somewhere in an admin account that the NetworkService/Basic is missing. Again no exception under minimal account.
James