I have gone through the similar questions on Stack overflow.But still I am not able to fix my problem I am trying to access network shared printer through my windows service written in c#. When I run through development environment,it is working fine. But after creating a installer and run like it as a background service that time I am getting error like below **
"System.Printing.PrintServerException: An exception occurred while creating the PrintServer object. Win32 error: Access is denied"
**
Here I have given my code
using (PrintServer networkPrintServer = new PrintServer(networkPrinterServer))
{
using (PrintQueue networkPrintQueue = new PrintQueue(networkPrintServer, networkPrinterName,PrintSystemDesiredAccess.AdministratePrinter
))
{
PrintSystemJobInfo printJob = networkPrintQueue.AddJob(networkPrinterName);
networkPrintQueue.Refresh();
printJob.Refresh();
printJob.JobStream.Write(bytesToPrint, 0, bytesToPrint.Length);
printJob.JobStream.Close();
return PrinterSuccessfullyCompletedPrintJob;
}
}
Try to run your service from any windows Administrator account role.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.