Sign in to follow this  
Followers 0
Bubnoff

Printer management .... to save trees.

15 posts in this topic

#1 ·  Posted (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.

#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 by Bubnoff

[quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote]

Share this post


Link to post
Share on other sites



...i'm confused

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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...

Bubnoff

So 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...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Wouldn't it need to Cancel the document instead of Delete?


Aha.. I have unlocked it's secrets.. world domination is within my grasp...

Share this post


Link to post
Share on other sites

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 left

it as a placeholder so people looking on would know what I was trying to do. I'll use Cancel instead from now

on.

Thanks for the suggestion..........

Bubnoff


[quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote]

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 and

still 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 insulting

jargon one by one all the gurus bend over and grab their ankles and start helping him build a bot.

I suspect voodoo......

Bubnoff

Edited by Bubnoff

[quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote]

Share this post


Link to post
Share on other sites

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.335

This 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]

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

#15 ·  Posted (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 in

the 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 seen

show an object "objprint.Delete_". I'm no WMI guru, so its greek to me. So I'll be looking into this

and 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. Reflected

in recently editted code above. Beware!!! Under construction...

Edited by Bubnoff

[quote] Use educated speculation to create the illusion of pleasure ...Its the closest you'll ever get.- Anon [/quote]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0