JSI Tip 9675. SetPrinter.exe is a command-line tool to set configurations or states of local or remote printers.

Jerold Schulman

August 25, 2005

5 Min Read
ITPro Today logo in a gray background | ITPro Today


Download SetPrinter.exe, a command-line tool to set configurations or states of local and remote printers, for an individual printer or for all printers on a print server.

SetPrinter uses the following general syntax:setprinter [/show] {\server | \serverprinter | printer} {printer_info_level} [keyword="[- | +]value" ...] [{pause | resume | purge | setstatus}]setprinter {/help | /examples} {printer_info_level}When you open a CMD.EXE windows and type setprinter /?, you receive:

Syntax:  SetPrinter <\server|printer>  [ ...] []     or  SetPrinter -help      or  SetPrinter -examples      or  SetPrinter -show <\server|printer> where:  \server : change all local printers on this server ("" for local machine)  printer  : change this printer (printer or \serverprinter)  level    : PRINTER_INFO level (0 - 9).  data     : (optional) Level specific data in 'keyword=value keyword=value'              format.  Data is unchanged for keywords not specified.  cmd      : (optional, but must be last if present) one of:               "pause", "resume", "purge", "setstatus"  -help    : show format of data for   -examples: show usage examples for   -show    : show current settings (no changes applied)

printer_info_level Specifies the printer information level. The valid values are 0 though 9. The printer information level is part of the SetPrinter application programming interface (API).

Level

Structure

0

If the Command parameter is PRINTER_CONTROL_SET_STATUS, pPrinter must contain a DWORD value that specifies the new printer status to set. For a list of the possible status values, see the Status member of the PRINTER_INFO_2 structure. Note that PRINTER_STATUS_PAUSED and PRINTER_STATUS_PENDING_DELETION are not valid status values to set.

If Level is 0, but the Command parameter is not PRINTER_CONTROL_SET_STATUS, pPrinter must be NULL.

2

A PRINTER_INFO_2 structure containing detailed information about the printer.

3

Windows NT/2000/XP: A PRINTER_INFO_3 structure containing the printer's security information.

4

Windows NT/2000/XP: A PRINTER_INFO_4 structure containing minimal printer information, including the name of the printer, the name of the server, and whether the printer is remote or local.

5

A PRINTER_INFO_5 structure containing printer information such as printer attributes and time-out settings.

6

Windows 2000/XP: A PRINTER_INFO_6 structure specifying the status value of a printer.

7

Windows 2000/XP: A PRINTER_INFO_7 structure. The dwAction member of this structure indicates whether SetPrinter should publish, unpublish, re-publish, or update the printer's data in the directory service.

8

Windows 2000/XP: A PRINTER_INFO_8 structure specifying the global default printer settings.

9

Windows 2000/XP: A PRINTER_INFO_9 structure specifying the per-user default printer settings.


Examples:

setprinter -examples 0Used to pause, resume, or purge (all jobs from) a print queue.To see current settings:  SetPrinter -show PrinterName 0To pause a printer:  SetPrinter PrinterName 0 pauseTo resume a printer:  SetPrinter PrinterName 0 resumeTo delete all jobs from all printers on the local machine:  SetPrinter "" 0 purgeTo indicate all printers on a remote machine are not available:  SetPrinter \ServerName 0 "status=|notavailable" setstatusTo indicate all printers on a remote machine are no longer offline:  SetPrinter \ServerName 0 "status=|~offline" setstatussetprinter -examples 1  SetPrinter does not support the setting of Level 1 values.To see current settings:  SetPrinter -show PrinterName 1setprinter -examples 3Used to configure most print queue settings.To see current settings:  SetPrinter -show PrinterName 2To share a printer:  SetPrinter PrinterName 2 "pShareName=ShareName" "Attributes=+shared"To unshare a printer:  SetPrinter PrinterName 2 "Attributes=|~shared"To change a printer name:  SetPrinter PrinterName 2 "pPrinterName=New name"To make a pooled printer (one queue, multiple ports):  SetPrinter PrinterName 2 "pPortName=LPT1,LPT2,IP_10.0.0.0"To set all printers on the local machine to spool RAW only,keep printed jobs,and print spooled jobs first:  SetPrinter "" 2 "Attributes=|rawonly keepjobs docompletefirst"To enable long-side duplex printing and collation on all printers on a remotemachine (dmFields settings are optional since they are implicitly set):  SetPrinter \ServerName 2 "pdevmode=dmduplex=2,dmCollate=1,dmFields=|duplex collate"To set default paper size to A4 on all local printers:(for current user.  Use level 8 to set global default)  SetPrinter "" 2 "pdevmode=dmPaperSize=9, dmPaperLength=2970, dmPaperWidth=2100, dmFormName=A4"setprinter -examples 3Used to set print queue security.  Note: Security settings can only be set as a whole.  Nosupport is provided for partial modifications.To see current settings:  SetPrinter -show PrinterName 3To change security settings (see "Security Descriptor String Format" in MSDN or SDKdocs for details):*** WARNING: this could make the print queue inaccessable and require the use of a registry editor to fix ***

SetPrinter PrinterName 3 "pSecurityDescriptor=O:BAG:DUD:(A;CIIO;RC;;;CO)(A;OIIO;GA;;;CO)(A;;SWRC;;;WD)(A;CIIO;GX;;;WD)(A;;LCSWSDRCWDWO;;;BA)(A;OICIIO;GA;;;BA)(A;;LCSWSDRCWDWO;;;PU)(A;OICIIO;GA;;;PU)"

To leave the settings unchanged (but what's the point then):  SetPrinter PrinterName 3 "pSecurityDescriptor=NULL"setprinter -examples 4Not often used since level 2 has this and more control (but is slower).To see current settings:  SetPrinter -show PrinterName 4To change a printer name:  SetPrinter PrinterName 4 "pPrinterName=newname"To unshare a printer:  SetPrinter PrinterName 4 "Attributes=|~shared"setprinter -examples 5Used primarily to change timeout values for LPT ports.To see current settings:  SetPrinter -show PrinterName 5To set retry timeout to 15 minutes (900 seconds):  SetPrinter PrinterName 5 "TransmissionRetryTimeout=900"To change a printer name:  SetPrinter PrinterName 5 "pPrinterName=newname"To change a print queue's port:  SetPrinter PrinterName 5 "pPortName=NewPortName"setprinter -examples 6Used to set a print queue's status.  Same as level 0 with SetStatus command.To see current settings:  SetPrinter -show PrinterName 6To indicate a printer is not available:  SetPrinter PrinterName 6 "dwstatus=|notavailable"To indicate all printers on a remote machine are no longer offline:  SetPrinter \ServerName 6 "dwstatus=|~offline"setprinter -examples 7Used to publish or unpublish a printer in the ActiveDirectory.To see current settings:  SetPrinter -show PrinterName 7To publish a printer:  SetPrinter PrinterName 7 "dwAction=publish"To unpublish all printers on the local machine:  SetPrinter "" 7 "dwAction=unpublish"To republish all printers on a remote machine:  SetPrinter \ServerName 7 "dwAction=republish"setprinter -examples 8Used to set global document printing defaults.To see current settings:  SetPrinter -show PrinterName 8To disable collation on a printer:  SetPrinter PrinterName 8 "pdevmode=dmCollate=0"To enable long-side duplex printing and collation on all printers on a remotemachine (dmFields settings are optional since they are implicitly set):  SetPrinter \ServerName 8 "pdevmode=dmduplex=2,dmCollate=1,dmFields=|duplex collate"To set default paper size to A4 on all local printers:  SetPrinter "" 8 "pdevmode=dmPaperSize=9, dmPaperLength=2970, dmPaperWidth=2100, dmFormName=A4"setprinter -examples 9Used to set current-user document printing defaults.  Not really useful for remote servers/printers since there is no associated current user.To see current settings:  SetPrinter -show PrinterName 9To disable collation on a printer:  SetPrinter PrinterName 9 "pdevmode=dmCollate=0"To enable long-side duplex printing and collation on all printers(dmFields settings are optional since they are implicitly set):  SetPrinter "" 9 "pdevmode=dmduplex=2,dmCollate=1,dmFields=|duplex collate"To set default paper size to A4 on all local printers:  SetPrinter "" 9 "pdevmode=dmPaperSize=9, dmPaperLength=2970, dmPaperWidth=2100, dmFormName=A4"



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like