Link to home
Create AccountLog in
Avatar of sunhux
sunhux

asked on

help to enhance VB & Windows batch script to release print job one by one to spooler

Refer to below 2 scripts.  The scripts have one issue:
they will clear away everything from
   c:\WINdows\System32\spool\PRINTERS\*.*

However, it's only certain print job that cause the print
spooler to stop/crash.  However, there's no way to check
which print job is the cause of the spooler to stop/crash.


So I'll need to enhance the scripts such that whenver
the print spooler is found to have stopped/crashed,

1. move all its jobs to another temporarily folder
2. stop all new print jobs from going to spooler but
    put them in another temporary folder, say folder2
3. (re)start up the print spooler
4. move/release the print job one by one to the
    spooler, each time releasing one job, test that
    the print job has completed before releasing
    (ie move from the temporary folder) the next
    job.  
5. If a print job cause the spooler to stop, then
    move the current job to an 'error' folder, never
    to print the job anymore.  Then start up the
    spooler again & release the next job
6. Keep iterating/repeating steps 4 & 5 till all
    print jobs are completed
7. Then start releasing 'new' print jobs from
    folder2
8. Continue checking for status of spooler & if
    it stops/crashes again, repeat steps 1-7 above


*********** Windows batch script to check every 15 secs ************

StartSpooler.bat (run from Windows Scheduler every minute)
=============
sc queryex Spooler | find/i "Running"
if NOT %ERRORLEVEL% == 0 goto startsvc
 
ping localhost -n 15
sc queryex Spooler | find/i "Running"
if NOT %ERRORLEVEL% == 0 goto startsvc
 
ping localhost -n 15
sc queryex Spooler | find/i "Running"
if NOT %ERRORLEVEL% == 0 goto startsvc
 
ping localhost -n 15
sc queryex Spooler | find/i "Running"
if NOT %ERRORLEVEL% == 0 goto startsvc
 
exit
 
:startsvc
move c:\WINdows\System32\spool\PRINTERS\*.*  d:\temp\spool
net stop spooler
net start spooler
exit

Open in new window


============= VB script ==================
strComputer = "."
 
strService = " 'SPOOLER' "
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" _
 & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
 ("Select * from Win32_Service Where Name ="_
 & strService & " ")
For Each objService in colListOfServices
  If objService.status <>"OK" or objService.state <>"Running" then
    objService.StartService()
    WScript.Echo strService & " service has restarted"
  End If
WScript.Quit
Next

Open in new window

Avatar of sunhux
sunhux

ASKER

Oh, I forgot to elaborate that whenever a user spool a print job,
2 files will be created in c:\WINdows\System32\spool\PRINTERS\
folder: an spl & an shd file.  Eg below shows 3 print jobs:
111.spl
111.shd
112.spl
112.shd
113.spl
113.shd
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of sunhux

ASKER

Not quite what I'm looking for.

What I need is such that the scripts would do the
following:

1. move all its jobs to another temporarily folder
2. stop all new print jobs from going to spooler but
    put them in another temporary folder, say folder2
3. (re)start up the print spooler
4. move/release the print job one by one to the
    spooler, each time releasing one job, test that
    the print job has completed before releasing
    (ie move from the temporary folder) the next
    job.  
5. If a print job cause the spooler to stop, then
    move the current job to an 'error' folder, never
    to print the job anymore.  Then start up the
    spooler again & release the next job
6. Keep iterating/repeating steps 4 & 5 till all
    print jobs are completed
7. Then start releasing 'new' print jobs from
    folder2
8. Continue checking for status of spooler & if
    it stops/crashes again, repeat steps 1-7 above
Avatar of sunhux

ASKER

partial