WinBatch Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: MW4 on June 25, 2013, 11:02:27 am

Title: Clearing a printers internal buffer?
Post by: MW4 on June 25, 2013, 11:02:27 am
I have a Panasonic KX-P2023 dot matrix printer that we use for forms.

When we have a job that gets misaligned during a print that we have to stop mid-stream, we turn off the printer, then go into printers and kill the job (XP.)

When we power the printer back up it keeps printing! It must have an internal buffer that needs to be cleared. Is there anything that I could program that would kill it without powering the printer down and having to kill the job manually?

I figured that maybe someone here would have come across this before.

Thanks, Mike
Title: Re: Clearing a printers internal buffer?
Post by: Deana on June 25, 2013, 11:13:50 am
You mentioned Windows XP. Maybe give this code a try:
Code: Winbatch
; Delete Print Jobs

; Stop the Spooler Service
AddExtender("wwwnt34i.dll")
aService = "Spooler"
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
   Endif
Endif

; Delete files in Spool
FileDelete( DirWindows(0):'\system32\spool\printers\*.shd' )
FileDelete( DirWindows(0):'\system32\spool\printers\*.spl' )

; Restart the Spooler Service
wntSvcStart("", aService, 0, "", "") ; start the Spooler service
Exit
Title: Re: Clearing a printers internal buffer?
Post by: rw_baker on June 26, 2013, 06:40:34 am
Deana,

I tried your code on Windows 7 and it doesn't work...you did specify it was for XP.  Could you alter the code for "7"?

I would like to use it, if possible.

RW Baker
Title: Re: Clearing a printers internal buffer?
Post by: Deana on June 26, 2013, 07:47:39 am
Deana,

I tried your code on Windows 7 and it doesn't work...you did specify it was for XP.  Could you alter the code for "7"?

I would like to use it, if possible.

RW Baker

You mentioned in your original message you were working with Windows XP, so I did some research and wrote the code for you.

Sorry I don't have a code sample for Windows 7.  I recommend doing some research using WMI to delete the file in the printer spool.

Here are some tech articles that should help get you started:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Tutorials+Printing.txt
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Printing~Information+Pause~Printer~Queue.txt
Title: Re: Clearing a printers internal buffer?
Post by: Deana on June 26, 2013, 10:57:42 am
Ok here is an undebugged code sample I came up with for Windows 7:

Code: Winbatch
; Delete Print Jobs

; Stop the Spooler Service
AddExtender("wwwnt34i.dll")
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 )
FileDelete( DirWindows(0):'\system32\spool\printers\*.shd' )
FileDelete( DirWindows(0):'\system32\spool\printers\*.spl' )
IntControl( 92, "revert", oldvalue, 0, 0 )

; Restart the Spooler Service
wntSvcStart("", aService, 0, "", "") ; start the Spooler service
Exit
Title: Re: Clearing a printers internal buffer?
Post by: rw_baker on June 27, 2013, 09:57:31 am
Deana,

Your code does the job!  Thanks a lot...

RW Baker
Title: Re: Clearing a printers internal buffer?
Post by: Deana on June 27, 2013, 10:10:16 am
Glad to hear, it worked for you! I created a tech article with the code: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Printing~Information+Delete~Print~Jobs.txt