Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello.
I write following code for get printer status in constructor class.my printers are turn on but are no paper or low toner or etc.
i want get errors for low paper or no paper or no toner and etc runtime.

C#
class PrinterStatus
    {

        public PrinterStatus()
        {
            String statusReport = "";
            PrintServer myPS = new PrintServer();
            PrintQueueCollection myPrintQueues = myPS.GetPrintQueues();
            foreach (PrintQueue pq in myPrintQueues)
            {
                pq.Refresh();
                {
                    statusReport = pq.Name;
                    if ((pq.QueueStatus & PrintQueueStatus.PaperProblem) == PrintQueueStatus.PaperProblem)
                    {
                        statusReport = statusReport + "Has a paper problem. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.NoToner) == PrintQueueStatus.NoToner)
                    {
                        statusReport = statusReport + "Is out of toner. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.DoorOpen) == PrintQueueStatus.DoorOpen)
                    {
                        statusReport = statusReport + "Has an open door. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.Error) == PrintQueueStatus.Error)
                    {
                        statusReport = statusReport + "Is in an error state. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.NotAvailable) == PrintQueueStatus.NotAvailable)
                    {
                        statusReport = statusReport + "Is not available. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.Offline) == PrintQueueStatus.Offline)
                    {
                        statusReport = statusReport + "Is off line. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.OutOfMemory) == PrintQueueStatus.OutOfMemory)
                    {
                        statusReport = statusReport + "Is out of memory. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.PaperOut) == PrintQueueStatus.PaperOut)
                    {
                        statusReport = statusReport + "Is out of paper. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.OutputBinFull) == PrintQueueStatus.OutputBinFull)
                    {
                        statusReport = statusReport + "Has a full output bin. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.PaperJam) == PrintQueueStatus.PaperJam)
                    {
                        statusReport = statusReport + "Has a paper jam. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.Paused) == PrintQueueStatus.Paused)
                    {
                        statusReport = statusReport + "Is paused. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.TonerLow) == PrintQueueStatus.TonerLow)
                    {
                        statusReport = statusReport + "Is low on toner. ";
                    }
                    if ((pq.QueueStatus & PrintQueueStatus.UserIntervention) == PrintQueueStatus.UserIntervention)
                    {
                        statusReport = statusReport + "Needs user intervention. ";
                    }
                }
            }// end for each print queue 
        }
    }


but at runtime Isoutofpaper and paperproblem properties and etc are false.
Thanks.
Posted

You might want to try using WMI. However, some printers aren't very adept at updating their status. All I can suggest is to give it a shot, and I guarantee nothing.
 
Share this answer
 
v2
Hello.thanks for your solution.
my printer is thermal printer that paper roll sensor status is off.
windows not show any message when that is no paper.
my problem not solved.
 
Share this answer
 
Comments
Eddy Vluggen 14-Aug-11 15:40pm    
What's the brand/printer name and model? Does it support showing a "no paper"-message if you print from Microsoft Word?
That's handled at the OS-level. The printers driver will generate such a message if it is capable of detecting those situations. You generating the same message would be redundant, and have the user click the message away twice; once the message generated by the driver, once yours.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900