"Bill Gates" <BG****@microsoft.com> wrote in message news:uq**************@TK2MSFTNGP14.phx.gbl...
Thanks for the responses they have been very helpful, however still having a little problem as outlined below...
I have taken the code from
http://www.codeproject.com/csharp/cpimpersonation1.asp which is used to impersonate a user and implemented this in my project however i am still unable to print through a web service.
The code that I am using to try to print a report is...
------------------------------------------------------------------------------
private System.Security.Principal.WindowsImpersonationCont ext newUser;
newUser = ImpersonateUser("username", "domain", "password"); // where ImpersonateUser is taken from the CodeProject source
// New User
string sNewUser = System.Security.Principal.WindowsIdentity.GetCurre nt().Name; // Can use this to check the current user
// Run Print
PalletLabel pl = new PalletLabel(); // Crystal Report called PalletLabel.rpt
pl.PrintOptions.PrinterName = [PrinterName]; // PrinterName is the UNC path of the printer (ie \\MyServer\MyPrinter)
pl.PrintToPrinter(1,true,1,1); // Print the damn thing
------------------------------------------------------------------------------
When I call the web service and pass a printer i get the following error message
Error in File C:\DOCUME~1\dotNET\ASPNET\LOCALS~1\Temp\temp_bd4f3 ceb-6c6e-41b7-bbad-b938cfee7d62.rpt:
Request cancelled by the user.
the code fails at the line "pl.PrintToPrinter(1,true,1,1); // Print the damn thing"
Does anyone have any ideas about this???
If you want I could post a small app with my code in if you think that will help.
Now you only have created a new logon session, but a few questions remain:
- Was it successful? I mean how do you know it succeeded? What action is taken when it fails?
- Does the impersonating account has access to the remote printer share?
- What if the CR needs access to the HKCU of the impersonating user? (Note that it's hive is not loaded, you didn't load the users profile like I told you)
- What if there's a spooler/printer error message "displayed" when/before printing? Note that server side this message is not visible, and even if it was, who's gonna take the corrective action?
Willy.