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.

Dani AI

Generated

asked how to monitor print jobs and suggested using PrintQueue. Two practical routes: a managed .NET approach (System.Printing) that gives easy access to job snapshots, and a native/spooler approach (winspool.drv or WMI) for event-driven monitoring or service scenarios. The .NET objects (PrintSystemJobInfo) expose job ID, name, status and page counts you can read or refresh when needed. (learn.microsoft.com)

A minimal managed example (good for desktop/WPF apps):

using System.Printing;

var server = new LocalPrintServer();
using (var pq = server.GetPrintQueue("PrinterName"))
{
    pq.Refresh();
    var jobs = pq.GetPrintJobInfoCollection();
    foreach (PrintSystemJobInfo job in jobs)
    {
        Console.WriteLine($"ID:{job.JobIdentifier} Name:{job.JobName} Status:{job.JobStatus} Pages:{job.NumberOfPages}/{job.NumberOfPagesPrinted}");
    }
}

Caveat: classes in System.Printing are not supported for use inside Windows Services or ASP.NET — they can behave unpredictably there. If your monitor runs as a service, prefer the spooler/WMI route. (learn.microsoft.com)

If you need event-driven notifications or are writing a service, use the Win32 spooler API: open the printer, call FindFirstPrinterChangeNotification with the job flags you care about (for example PRINTER_CHANGE_ADD_JOB | PRINTER_CHANGE_SET_JOB | PRINTER_CHANGE_DELETE_JOB), wait on the returned handle, then call FindNextPrinterChangeNotification to get PRINTER_NOTIFY_INFO and query the job (GetJob/EnumJobs) for details. Remember to close the notification handle when done and handle the "discarded" overflow case by requesting a refresh. (learn.microsoft.com)

A third, often simpler option is WMI: subscribe to InstanceCreationEvent / InstanceDeletionEvent for Win32_PrintJob (ManagementEventWatcher) to see jobs appear/disappear and then read properties such as TotalPages or PagesPrinted. Note TotalPages/PagesPrinted may be 0 or change during processing depending on driver/spooler behavior, and you need appropriate printer permissions (Manage Documents / admin) to inspect or control others’ jobs — so treat page counts as advisory and combine notifications + a direct job query for the reliable final state. (learn.microsoft.com)

Just use the PrintQueue class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.