WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Printing Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Delete Print Jobs


Question:

How do I delete print jobs, stuck in the spool or just sent to an offline printer. I am having large problems with terminal services and printing and users sending jobs to the wrong printer, I am trying to create some scripts to delete the jobs sent to the wrong printer.

Answer:

Delete Print Jobs (from spooler) using the Win32 Network Extender:
; Delete Print Jobs

; Stop the Spooler Service
AddExtender("wwwnt34i.dll")
;aService = "Spooler" ;Win XP
aService = "Print Spooler" ;Win 7
state = wntSvcStatus("", aService, 0, 2) ; Get the current state of the service
If state==4 ; Service is running
   wntSvcControl("", aService, 0, 1) ; Stop the Service
   ; Wait for service to stop
   While state != 1
      TimeDelay(1)
        state = wntSvcStatus("", aService, 0, 2) ; get the current state of the service
   EndWhile
EndIf

; Delete files in Spool
oldvalue = IntControl( 92, "disable", 0, 0, 0 ); Disable File Redirection
FileDelete( DirWindows(0):'\system32\spool\printers\*.shd' )
FileDelete( DirWindows(0):'\system32\spool\printers\*.spl' )
IntControl( 92, "revert", oldvalue, 0, 0 ) ; Enable File Redirection

; Restart the Spooler Service
wntSvcStart("", aService, 0, "", "") ; start the Spooler service
Exit
If running on XP or newer, you may be able to accomplish this using WMI. Check out the CancelAllJobs method in the Win32_Printer Class.

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/cancelalljobs_method_in_class_win32_printer.asp?frame=true

Or you might be able to use the following command line.

First, Run queue view:

Run("rundll32","printui.dll,PrintUIEntry /o /n\\machine\printer")
Then send the keystrokes to 'cancel all'.
Article ID:   W16661
File Created: 2013:06:26:11:03:32
Last Updated: 2013:06:26:11:03:32