开发者

Access Denied when calling PrintQueue.Pause() method in C#.net

开发者 https://www.devze.com 2023-01-18 23:17 出处:网络
I\'m trying to pause a windows 7 print queue using C#.NET visual studio 2008. I have full administrator rights but when I run the following code to Pause the Queue it says Access is Denied. Please hel

I'm trying to pause a windows 7 print queue using C#.NET visual studio 2008. I have full administrator rights but when I run the following code to Pause the Queue it says Access is Denied. Please help me.

        LocalPrintServer lps = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
        //PrintServer lps = new PrintServer("\\\\NOTEBOOK-CI3开发者_Go百科", PrintSystemDesiredAccess.AdministratePrinter);
        lps.Commit();
        PrintQueue queue = lps.GetPrintQueue(listBox1.SelectedItem.ToString());
        if (!queue.IsPaused)
            queue.Pause();

        queue.Commit();
        lps.Commit();


I had the same problem, so for me this was the best solution:

PrintS = new PrintServer();
PrintQ = new PrintQueue(PrintS, PrinterName, PrintSystemDesiredAccess.AdministratePrinter);
PrintQ.Pause();

Tested with local PDF-Printer


I'm not sure but have you tried to change LocalPrinterServer to PrinterServer? Take a look at http://www.visualbasicask.com/visual-basic-language/printqueuepause.shtml.
He had the exact same problem and could solve it by using PrintSystemDesiredAccess.AdministrateServer (which you do use). The only difference is that you're using LocalPrinterServer instead of PrinterServer.


Are you running your website as 4.0? I ran into issues when we upgraded our website from 3.5 to 4.0 Framework. The Print Purging functionality stopped working in the 4.0 Framework. Ultimately I ended up creating a web service that used the 3.5 framework and had the 4.0 website communicate the printer it wanted to purge to the 3.5 web service.

(Sorry to revive this thread, this was one of the threads I stumbled onto when I was looking for an answer. Figured I'd post this if it helps someone that runs into the same situation)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号