PrintServer object. Access is denied. On Server 2016

j g 6 Reputation points
2021-10-22T19:32:34.577+00:00

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();
    }
}
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
{count} votes