Link to home
Start Free TrialLog in
Avatar of nosliwde99
nosliwde99

asked on

Delete most recent Windows print job in AutoIT (via WMIC ?)

I want to delete the most recently submitted print job with a particular document name.  I will know its submission time to within a second.

I'm working in AutoIT.  Invoking WMIC looks like a promising option...
...however I don't understand how date formats are handled in WMIC yet.
   
So, I was expecting to be able to do something like
#include <Process.au3>
$ReturnValue = _RunDos('WMIC Printjob WHERE (Document="ScreenPrint32 v3.5" AND TimeSubmitted > 20140404003556.000) Delete')
ConsoleWrite("$ReturnValue = " & $ReturnValue & @CRLF)

Open in new window

No dice.  

So, just working in a command prompt, the following does work if the time value is compared as an '=' and I copy and paste in the exact TimeSubmitted in quotes. ('delete' changed to 'get' for ease of testing)  But I want to be able to do a time comparison of '>' and supply my own date.
WMIC Printjob WHERE (Document="ScreenPrint32 v3.5" AND TimeSubmitted = '20140404003556.912000-240') GET

Open in new window

Is there an easy way to identify & delete the most recent job without even messing with TimeSubmitted?
Even if I get the WMIC aspect sorted out (for which I'd be way grateful), I won't get a return value in AutoIT to know of success.  (When I plug in functional WMIC printjob delete statements, the return value is always 0.)  What's the best overall approach?
Thank you.
Ed
SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nosliwde99
nosliwde99

ASKER

Thank you both.
Joe, I've done this approach before, and the print window has behaved squirrely afterward.  I'm wanting to hang with something rock solid.  Sorry I didn't mention this in the op.
Matrixnz, I think this is just what I'm looking for...will dig in tomorrow.
> print window has behaved squirrely afterward

Hmmm, interesting! I haven't seen bad behavior after stopping the spooler, deleting spool files, then restarting the spooler. Anyway, good luck with Jarvis Stubblefield's script as modified by matrixnz. I'll keep an eye on this thread to see how it goes for you. Regards, Joe
The original code is part of the following excellent UDF by JSPatriot if anyone is interested.
http://www.autoitscript.com/forum/topic/29404-computer-info-udfs/.  I find it a good place to start to get references to wmi objects.

Cheers
Hi nosliwde99

Were you able to test the code above?  Do you require any additional assistance?

Cheers
Sorry for the delay.  Was slammed with a different project that pulled me in a different direction.  Just re-surfacing.
matrixnz, this is perfect!  Thank you so much.