Click to Rate and Give Feedback
Windows GDI
SetJob

The SetJob function pauses, resumes, cancels, or restarts a print job on a specified printer. You can also use the SetJob function to set print job parameters, such as the print job priority and the document name.

Windows 95/98/Me: You can use the SetJob function to give a command to a print job, or to set print job parameters, but you cannot do both in the same call. Thus, when the Command parameter is nonzero, the function ignores the Level and pJob parameters. To set print job parameters, you must set Command to 0.

Windows NT/2000/XP/Vista: You can use the SetJob function to give a command to a print job, or to set print job parameters, or to do both in the same call. The value of the Command parameter does not affect how the function uses the Level and pJob parameters. Also, you can use SetJob with JOB_INFO_3 to link together a set of print jobs. See Remarks for more information.

BOOL SetJob(
  HANDLE hPrinter,  // handle to printer object
  DWORD JobId,      // print job identifier
  DWORD Level,      // information level
  LPBYTE  pJob,     // job information buffer
  DWORD Command     // job command value
);

Parameters

hPrinter
[in] Handle to the printer object of interest. Use the OpenPrinter, OpenPrinter2, or AddPrinter function to retrieve a printer handle.
JobId
[in] Identifier that specifies the print job. You obtain a print job identifier by calling the AddJob function or the StartDoc function.

Windows NT/2000/XP/Vista: If the Level parameter is set to 3, the JobId parameter must match the JobId member of the JOB_INFO_3 structure pointed to by pJob.

Level
[in] Specifies the type of job information structure pointed to by the pJob parameter.

All versions of Windows: You can set the Level parameter to 0, 1, or 2. When you set Level to 0, pJob should be NULL. Use these values when you are not setting any print job parameters.

Windows NT/2000/XP/Vista: You can also set the Level parameter to 3.

Windows Vista: You can also set the Level parameter to 4.

Windows 95/98/Me: The function pays attention to this parameter only if the Command parameter is 0. If Command is nonzero, the function ignores this parameter and the pJob parameter.

pJob
[in] Pointer to a structure that sets the print job parameters.

All versions of Windows: pJob can point to a JOB_INFO_1 or JOB_INFO_2 structure.

Windows NT/2000/XP/Vista: pJob can also point to a JOB_INFO_3 structure. You must have JOB_ACCESS_ADMINISTER access permission for the jobs specified by the JobId and NextJobId members of the JOB_INFO_3 structure.

Windows Vista: pJob can also point to a JOB_INFO_4 structure.

If the Level parameter is 0, pJob should be NULL.

Windows 95/98/Me: The function pays attention to this parameter only if the Command parameter is 0. If Command is nonzero, the function ignores this parameter and the Level parameter.

Command
[in] Specifies the print job operation to perform. This parameter can be one of the following values.
Value Meaning
JOB_CONTROL_CANCEL Windows 95/98/Me, Windows NT 3.51 and earlier: Delete the print job.

Windows NT 4.0 and later: Do not use. To delete a print job, use JOB_CONTROL_DELETE.

JOB_CONTROL_PAUSE Pause the print job.
JOB_CONTROL_RESTART Restart the print job. A job can only be restarted if it was printing.
JOB_CONTROL_RESUME Resume a paused print job.
JOB_CONTROL_DELETE Windows NT 4.0 and later: Delete the print job.
JOB_CONTROL_SENT_TO_PRINTER Windows NT 4.0 and later: Used by port monitors to end the print job.
JOB_CONTROL_LAST_PAGE_EJECTED Windows NT 4.0 and later: Used by language monitors to end the print job.
JOB_CONTROL_RETAIN Windows Vista and later: Keep the job in the queue after it prints.
JOB_CONTROL_RELEASE Windows Vista and later: Release the print job.

Windows 95/98/Me: If you are using the SetJob function to set print job parameters, you must set the Command parameter to 0.

Windows NT/2000/XP/Vista: You can use the same call to the SetJob function to set print job parameters and to give a command to a print job. Thus, Command does not need to be 0 if you are setting print job parameters, although it can be.

Return Values

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero.

Remarks

You can use the SetJob function to set various print job parameters by supplying a pointer to a JOB_INFO_1, JOB_INFO_2, JOB_INFO_3, or JOB_INFO_4 structure that contains the necessary data.

Windows 95/98/Me: When you use the function to set print job parameters, you must set the Command parameter to 0.

To remove or delete all of the print jobs for a particular printer, call the SetPrinter function with its Command parameter set to PRINTER_CONTROL_PURGE.

The following members of a JOB_INFO_1, JOB_INFO_2, or JOB_INFO_4 structure are ignored on a call to SetJob:

JobId, pPrinterName, pMachineName, pDrivername, Size, Submitted, Time, and TotalPages.

You must have PRINTER_ACCESS_ADMINISTER access permission for a printer in order to change a print job's position in the print queue.

If you do not want to set a print job's position in the print queue, you should set the Position member of the JOB_INFO_1, JOB_INFO_2, or JOB_INFO_4 structure to JOB_POSITION_UNSPECIFIED.

Windows NT/2000/XP/Vista: Use the SetJob function with the JOB_INFO_3 structure to link together a set of print jobs (also known as a chain). This is useful in situations where a single document consists of several parts that you want to render separately. To print jobs A, B, C, and D in order, call SetJob with JOB_INFO_3 to link A to B, B to C, and C to D.

If you link print jobs, note the following:

  • Jobs can be added to the beginning or end of a chain.
  • All jobs in the chain must have the same data type.
  • The chain must be completely linked before spooling begins, otherwise the spooler may print and delete spooled jobs before you link them all. There are two ways to keep the chain from printing prematurely:
    • Pause the first job in the chain until the chain is completely linked. The paused state of the first job governs the state of all jobs in the chain.
    • Keep the first job incomplete, that is, do not call EndDoc or ScheduleJob for the first job. However, if 'print while spooling' is enabled (the default), this method blocks the port while the chain is built, which also prevents the printing of non-related jobs.
  • The application must handle the case where the user deletes a job in the chain before the chain finishes printing. GetLastError returns INVALID_PARAMETER when a JobID does not exist.

Windows 95/98/Me: SetJobW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Requirements

  Windows NT/2000/XP/Vista: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Winspool.h; include Windows.h.
  Library: Use Winspool.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode.

See Also

Printing and Print Spooler Overview, Printing and Print Spooler Functions, AddJob, GetJob, OpenPrinter, SetPrinter, JOB_INFO_1, JOB_INFO_2, JOB_INFO_3, JOB_INFO_4


Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker