question

jg-6461 avatar image
0 Votes"
jg-6461 asked JialeXueMSFT-4441 commented

PrintServer object. Access is denied. On Server 2016

The following code works on my local computer, but not when I run it on my admin account on Windows Server 2016.
Why?
I read that one of the problems might be that the Windows Feature "Print and Document Services" needs to be installed. It is on my local machine but not on the Windows Server. Not positive this is needed. Tried to install it, and that failed. Stuck.


 using (System.Printing.PrintServer ps = 
     new System.Printing.PrintServer(System.Printing.PrintSystemDesiredAccess.AdministratePrinter)) {
    
     using (System.Printing.PrintQueue pq = new System.Printing.PrintQueue(ps, "Our Printer 1"
        ,System.Printing.PrintSystemDesiredAccess.AdministratePrinter)) {
        pq.Purge();
     }
 }


dotnet-csharp
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @jg-6461,
What do you mean by invalid? Does an error message pop up? Can you paste the error message? What is your local system environment?

0 Votes 0 ·
jg-6461 avatar image jg-6461 JialeXueMSFT-4441 ·

Throws an exception "Access Denied".

"An exception occurred while creating the PrintServer object. Win32 error: Access is denied."

0 Votes 0 ·

Hi @jg-6461,
I find a related question about System.Printing.PrintServerException: An exception occurred while creating the PrintServer object. Win32 error: Access is denied.
But you run it on your admin account. And you run it well on your local computer.
The problem should be caused by "Print and Document Services".
You need to install it correctly.
Best Regards,
Jiale Xue

0 Votes 0 ·
Show more comments

0 Answers