tags:

views:

111

answers:

1

Hello guyz, 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.

+1  A: 

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.

Jack B Nimble
It seems like polling, But it slows the system. If I can hook to winspool I can use event. Thanks
Barun
I am very much appreciate your help. Thanks for reply.
Barun