views:

46

answers:

1

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();
+1  A: 

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
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
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
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
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