3.2.4.2.3 Enumerating Jobs on a Printer

To enumerate the jobs that are currently queued to a printer, the print client performs the following steps:

  1. Invoke RpcOpenPrinter, supplying the name of the target printer in the pPrinterName parameter and an AccessRequired value that includes PRINTER_ACCESS_USE.

  2. Using the printer handle that was obtained from RpcOpenPrinter:

    1. Set a local job position context to the desired starting index, typically zero.

    2. Set a local number of jobs to return in a single operation.<404>

    3. Until an RpcEnumJobs call returns with a success status and a pcReturned pointing to a value of zero, or until the expected set of jobs has been returned:

      1. Invoke RpcEnumJobs, supplying the job position context in FirstJob, the number of jobs to return in a call in NoJobs, the desired information level in Level, a pointer to the job information buffer in pJob, the size of the job information buffer in cbBuf, a pointer to a variable to store the required buffer size in pcbNeeded, and a pointer to a variable to store the number of job information structures returned in pcReturned.

      2. While RpcEnumJobs returns with ERROR_INSUFFICIENT_BUFFER [MS-ERREF]:

        1. Allocate a new job information buffer with the size returned in pcbNeeded.

        2. Invoke RpcEnumJobs, supplying the job position context in FirstJob, the number of jobs to return in a call in NoJobs, the desired information level in Level, a pointer to the job information buffer in pJob, the size of the job information buffer in cbBuf, a pointer to a variable to store the required buffer size in pcbNeeded, and a pointer to a variable to store the number of job information structures in pcReturned.

        Note: Because the number of jobs can change at any time, the client SHOULD be prepared to receive ERROR_INSUFFICIENT_BUFFER even after allocating the correct buffer size the first time.

      3. Increase the local job position context by the value supplied in pcReturned.

  3. The client SHOULD invoke RpcClosePrinter with the printer handle obtained from RpcOpenPrinter or repeat step 2 if there are further job enumeration requests to make.