开发者

c# : How to Monitor Print job Using 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 page开发者_如何学Pythons. 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.


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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜