c#:如何使用 winspool_drv 监控打印作业 [英] c# : How to Monitor Print job Using winspool_drv

查看:154
本文介绍了c#:如何使用 winspool_drv 监控打印作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近在做一个系统监控工具.为此,我需要一个班级来监视打印作业.比如打印什么时候开始,成功与否,多少页.我知道我可以使用 winspool.drv 做到这一点.但不知道如何.我已经进行了广泛的搜索,但没有运气.任何代码/建议都可能非常有帮助.谢谢.

Recently I am making a system monitoring tool. For that I need a class to monitor print job. Such as when a print started, is it successful or not, how many pages. I know that I can do it using winspool.drv. But dont how. I've searched extensively but having no luck. Any code/suggestion could be very helpful. Thanks.

推荐答案

嗯,我不知道 winspool.drv,但您可以使用 WMI 来获取打印机的状态.以下是使用 Win32_Printer 的示例.

Well I don't know about the winspool.drv, but you can use the WMI to get the status of the printer. Here is an example of the using Win32_Printer.

PrintDialog pd = new PrintDialog();
pd.ShowDialog();
PrintDoc.PrinterSettings = pd.PrinterSettings;
PrintDoc.PrintPage += new PrintPageEventHandler(PrintDoc_PrintPage);
PrintDoc.Print();

object status = Convert.ToUInt32(9999);
while ((uint)status != 0) // 0 being idle
{
    ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_Printer where Name='" + pd.PrinterSettings.PrinterName + "'");
    foreach (ManagementObject service in mos.Get())
    {
    status = service.Properties["PrinterState"].Value;
    Thread.Sleep(50);
    }
}

如果您不使用 PrintDialog 对象(选择打印机),您可以运行 WMI 查询,它将返回系统中的所有打印机.

If you don't use the PrintDialog object (to choose a printer) you can run the WMI query and it will return all the printers in the system.

这篇关于c#:如何使用 winspool_drv 监控打印作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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