Bubnoff Posted September 9, 2006 Share Posted September 9, 2006 (edited) ***** Edit: Newest solution posted. Doesn't always trap print fast enough. Sometimes one sheet prints. Loops fine. Deletes print intermittently/partially. Faulty, but a dramatic improvement on my previous attempt.***** I'm working on a script for public printers (in a library) that will: 1. query/monitor the printer queue on a local computer. Needs to loop. 2. Filter print jobs according to size. (i.e. does nothing if the job is less than 10 pages). 3. Pauses print job if it exceeds the filter, then displays a msgbox with our printing policy and the 'resume' and 'cancel' buttons. 4. Resumes printing if 'resume' pressed or deletes the job if 'cancel' is pressed. Here is what I have so far after much trial and error, and with the help of the forums. expandcollapse popup#include <Process.au3> Global $objPrintJob, $colPrintJobs, $objWMIService, $OEvent, $var Global $stoploop = 0 $OEvent=ObjEvent("AutoIt.Error","nothing"); = onerror Resume Next _main() Func _main() $strcomputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & "\\" & $strcomputer & "\root\cimv2") If IsObj($objWMIService) then $colPrintJobs = $objWMIService.ExecNotificationQuery("Select * From __InstanceCreationEvent " _ & "Within 1 Where TargetInstance ISA 'Win32_PrintJob'") While 1 $objPrintJob = $colPrintJobs.NextEvent If $objPrintJob.TargetInstance.TotalPages > 1 Then $objPrintJob.TargetInstance.Pause $msg = MsgBox (17, "Print Notification",$objPrintJob.TargetInstance.Document) If $msg = 1 Then _resume() If $msg = 2 Then _cancel() Else $objPrintJob.TargetInstance.Resume EndIf WEnd Else MsgBox(0, "Error", "Unable to connect to PrintJob Creation Event") Exit EndIf EndFunc Func _resume() $objPrintJob.Resume _main() EndFunc Func _cancel() SplashTextOn("", "Stopping Print Spooler, please wait...", 150, 75) _RunDOS("NET STOP spooler") SplashOff() SplashTextOn("", "Clearing print job, please wait...", 150, 75) sleep(2000) FileDelete(@SystemDir & "\spool\PRINTERS\*.*") SplashOff() SplashTextOn("", "Starting Print Spooler, please wait...", 150, 75) _RunDOS("NET START spooler") SplashOff() MsgBox(64, "Done!", "Done", 3) _main() EndFunc Any help or suggestions would be greatly appreciated. I'm no guru. Thank you, Bubnoff ***** Recently revamped. I target the host queue after trapping the printjob. UNDER CONSTRUCTION!!!!!This is sort of like the final scene in "Enter the Dragon". "Enter the Dragon" is far more tasteful and elegant though. Edited October 10, 2006 by Bubnoff [quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote] Link to comment Share on other sites More sharing options...
NELyon Posted September 13, 2006 Share Posted September 13, 2006 ...i'm confused Link to comment Share on other sites More sharing options...
strate Posted September 13, 2006 Share Posted September 13, 2006 Everyone that is wanting to help others, is looking for people to help in the support forum..... I'm not sure but I believe the first part of your script needs to be in the loop also. INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station... Link to comment Share on other sites More sharing options...
strate Posted September 14, 2006 Share Posted September 14, 2006 I originally posted this in the support forum to no avail. I found several print scripts in this forum (Scripts and Scraps) and was hoping those folks might have some ideas having dealt with this problem already.But, thanks for the comments.Any advice anyone might have would be greatly appreciated...BubnoffSo my thought didn't work then? INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station... Link to comment Share on other sites More sharing options...
raedts Posted September 14, 2006 Share Posted September 14, 2006 i certanly don't think this project is boring, i just don't like replying to topics i don't know a awnser on, this doesn't help anyone. Link to comment Share on other sites More sharing options...
JaySquared Posted September 14, 2006 Share Posted September 14, 2006 Wouldn't it need to Cancel the document instead of Delete? Aha.. I have unlocked it's secrets.. world domination is within my grasp... Link to comment Share on other sites More sharing options...
Bubnoff Posted September 14, 2006 Author Share Posted September 14, 2006 Wouldn't it need to Cancel the document instead of Delete?Thanks Jay, but no, that doesn't seem to work either. I knew the .Delete wouldn't work as well but leftit as a placeholder so people looking on would know what I was trying to do. I'll use Cancel instead from nowon.Thanks for the suggestion..........Bubnoff [quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote] Link to comment Share on other sites More sharing options...
Bubnoff Posted September 14, 2006 Author Share Posted September 14, 2006 (edited) So my thought didn't work then?No, and actually I'd begun to wonder if I'd accidentally stumbled upon some sort of Autoit taboo.I've had a posting in support for quite some time and there hasn't been a single response. It's as though I'm getting the cold shoulder.Evilelf on the other hand, insults everybody, uses unintelligible gibberish sprinkled with profanity andstill gets the gurus to help him build a bot for a game (which is supposedly something gurus don't like to do.).Not only that, but he makes them decipher what he actually wants. Naturally, he'd never bothered with the help file, or bothered to try it himself first. Hmmmm.Check out his posts, its unbelievable the abuse people put up with then after 2 pages of insultingjargon one by one all the gurus bend over and grab their ankles and start helping him build a bot.I suspect voodoo......Bubnoff Edited September 17, 2006 by Bubnoff [quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote] Link to comment Share on other sites More sharing options...
Bubnoff Posted September 14, 2006 Author Share Posted September 14, 2006 C:\Documents and Settings\Support\Desktop2\remote project-Autoit\PrintPause.au3 (22) : ==> The requested action with this object has failed.: If $msg = 2 Then $objPrintJob.TargetInstance.Cancel If $msg = 2 Then $objPrintJob.TargetInstance.Cancel^ ERROR+>AutoIT3.exe ended.rc:0>Exit code: 0 Time: 77.335This is the error I get after trying to cancel the print job.And thanks again to anybody who's taken the time to look at this post and respond...Bubnoff [quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote] Link to comment Share on other sites More sharing options...
Pa Callender Posted September 23, 2006 Share Posted September 23, 2006 WMI doesn't have the functions .Terminate, .Cancel, .Delete, or anything of the sort, as far as I know. Only .Pause and .Resume exist. [size="4"]YOU SHALL NOT PARSE!![/size] Link to comment Share on other sites More sharing options...
strate Posted September 24, 2006 Share Posted September 24, 2006 http://www.activexperts.com/activmonitor/w...inting/servers/I believe that link should cover just about everything for you. You should just have to piece it together. INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station... Link to comment Share on other sites More sharing options...
Bubnoff Posted September 26, 2006 Author Share Posted September 26, 2006 WMI doesn't have the functions .Terminate, .Cancel, .Delete, or anything of the sort, as far as I know. Only .Pause and .Resume exist.That's what I was afraid of. I came up with the same roadblock using various wmi viewers.Pause and Resume. .... Back to the drawing board...... Thanks for posting Pa!!Bubnoff [quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote] Link to comment Share on other sites More sharing options...
Bubnoff Posted September 26, 2006 Author Share Posted September 26, 2006 http://www.activexperts.com/activmonitor/w...inting/servers/I believe that link should cover just about everything for you. You should just have to piece it together.It looks like I'll need to query win32_PrintJob instead of TargetInstance. Actually leave TargetInstance out of the equation maybe. I'll give it a shot.Thanks for the link.....Bubnoff [quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote] Link to comment Share on other sites More sharing options...
Pa Callender Posted September 28, 2006 Share Posted September 28, 2006 I've looked at www.activexperts.com and as I was browsing the site, I wondered if this script would catch just the jobs that the local user has started, local or remote, or would it only catch on a print server, and on a print server would it catch all jobs? Because libraries tend to use networked printers, and I wonder if the librarian would have all the notifications? Just a thought. [size="4"]YOU SHALL NOT PARSE!![/size] Link to comment Share on other sites More sharing options...
Bubnoff Posted September 30, 2006 Author Share Posted September 30, 2006 (edited) I've looked at www.activexperts.com and as I was browsing the site, I wondered if this script would catch just the jobs that the local user has started, local or remote, or would it only catch on a print server, and on a print server would it catch all jobs? Because libraries tend to use networked printers, and I wonder if the librarian would have all the notifications? Just a thought.This script is intended to catch only locally started printjobs. The script (.exe) would be submerged inthe registry on the patron's computer. I'd thought about using a print release station (or print server), but due to staffing and budget that's not an option. This is where I'm headed now, having looked at the examples on the link posted and some others:The first part traps the local job in the cue (this part successful, in this example), the second part (under construction) will either resume or delete the print (not successful.... yet). As someone earlier pointed out, there is no "delete" method for TargetInstance, and there doesn't appear to be one for Win32_PrintJob either, but, many of the examples I've seenshow an object "objprint.Delete_". I'm no WMI guru, so its greek to me. So I'll be looking into thisand posting updates for any WMI dieties to bestow virtues on etc..... To be continued..................***** I believe the solution to be: Trap print in cue, then purge the queue on associated computer. Reflectedin recently editted code above. Beware!!! Under construction... Edited October 10, 2006 by Bubnoff [quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now