Skip to Content
0
Former Member
Apr 21, 2011 at 10:44 AM

Impersonating NETWORK SERVICE as a domain user failed

264 Views

Hi.

Please help on this, coz our development team has absolutely NO clue on how to solve this, and yet it is an issue that MUST be solved.

We want to do server printing on the IIS server, one or many printers are attached to it.

We are not letting all users to print thru it (via our ASP.NET app), but we will see if the user's domain account has access right to this printer.

Let's say there will be a page to print report, there is a drop-down combo box to let users choose a printer

if the AD user account has no right to use the printer, the drop down list will not contain that printer's name

What we are doing is to impersonate the current process (i.e. w3wp) to the user's AD account,

and after the impersonation, enumerate the user a/c's printers. We have no problems on this, it's working.

Let's say user USER1 has access right to printer PRINTER1. So he can see PRINTER1 in the dropdown, and click "print".

After that, we execute:

rptDoc1.PrintOptions.PrinterName = "PRINTER1";

A COMexception is thrown "printername is invalid crRpt {047E0C9D-57F3-4007-9713-8BBB24D942C6}.rpt"

(Errorcode: -2147483135)

We are almost 100% certain that it is caused by crystal reports instead of a general printing/access rights issue,

coz we add the following code to find that out:

PrintDocument pdoc = new PrintDocument();
pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);
pdoc.PrinterSettings.PrinterName = strPrinterName;
pdoc.Print();       //  <------------------- Print (A)


this.RptDoc.PrintOptions.PrinterName = strPrinterName == "" ? GetServerPrinter() : strPrinterName;

this.RptDoc.PrintToPrinter(1, false, 0, 0);  //  <------------------- Print (B)

The line Print (A) WORKS, but not Print (B)

So, the same printer name is valid on the printdoc, but not on rptdoc.

Here are the specs:

IIS version: 7.5
.NET CLR: 4
w3wp identity: NETWORK SERVICE
Windows Server version: 2008 standard
Browser: IE8

Please help, I will provide more information if you need them