2

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", PrintSystemDesiredAccess.AdministratePrinter);
        lps.Commit();
        PrintQueue queue = lps.GetPrintQueue(listBox1.SelectedItem.ToString());
        if (!queue.IsPaused)
            queue.Pause();

        queue.Commit();
        lps.Commit();
Zerone
  • 566
  • 4
  • 10
  • 24
  • Found a solution information which might be relevant to my problem but I do not know how to apply it to my C#.NET application. Please take a look here http://www.developerfusion.com/code/7987/making-a-net-app-run-on-vista-with-administrator-priviledges/ – Zerone Oct 02 '10 at 15:51
  • Found another which explains the above completely. But it says that the command existed with with code 3. please help. Here are the suggested solution which I followed: http://bartdesmet.net/blogs/bart/archive/2006/10/28/Windows-Vista-_2D00_-Demand-UAC-elevation-for-an-application-by-adding-a-manifest-using-mt.exe.aspx – Zerone Oct 02 '10 at 16:19

3 Answers3

6

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

user2447995
  • 61
  • 1
  • 2
1

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.

Kamyar
  • 18,639
  • 9
  • 97
  • 171
  • I tried changing all LocalPrintServer and PrintServer and AdministrateServer and AdministratePrinter for all 4combinations possible. Still it gives the same Access Denied error at the point of QueueName.Pause() method is called. Thanks you very much for your quick reply. – Zerone Oct 02 '10 at 15:47
  • I found some info here but don't know how to apply it to my C#.Net application. http://www.developerfusion.com/code/7987/making-a-net-app-run-on-vista-with-administrator-priviledges/ – Zerone Oct 02 '10 at 15:48
  • Found another which explains the above completely. But it says that the command existed with with code 3. please help. Here are the suggested solution which I followed: http://bartdesmet.net/blogs/bart/archive/2006/10/28/Windows-Vista-_2D00_-Demand-UAC-elevation-for-an-application-by-adding-a-manifest-using-mt.exe.aspx – Zerone Oct 02 '10 at 16:20
  • Sounds very strange! Are trying to connect to a network printer? If the answer is no, then I definitely is a strange problem for me! – Kamyar Oct 02 '10 at 16:28
0

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)

Griff2k
  • 21
  • 3