如何在发送作业之前检查打印机状态? [英] how i can check printer status before sending a job ?

查看:136
本文介绍了如何在发送作业之前检查打印机状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我在构造函数类中编写以下代码来获取打印机状态.我的打印机已打开,但没有纸张,碳粉不足或其他原因. 我希望因缺纸,缺纸,无碳粉以及其他运行时间而出错.

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.

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



但是在运行时Isoutofpaper和paperproblem属性等是错误的.
谢谢.



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

推荐答案

在操作系统级别处理.如果打印机驱动程序能够检测到这些情况,则会生成这样的消息.您生成相同的消息将是多余的,并且让用户两次单击该消息;一旦驱动程序生成了消息,就由您生成.
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.


您可能想尝试使用WMI.但是,某些打印机并不十分擅长更新其状态.我所能建议的只是试一试,我不保证.
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.


Hello.谢谢您的解决方案.
我的打印机是热敏打印机,纸卷传感器状态为关闭.
没有纸时,windows不会显示任何消息.
我的问题没有解决.
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.


这篇关于如何在发送作业之前检查打印机状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆