Jump to content

Printer Management....with guilt trip script.


Bubnoff
 Share

Recommended Posts

I manage printers in several locations and am looking for ways in which to curtail paper waste. The following code is my attempt using Autoit and W.M.I..

#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")
    
    $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
    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

Here is the newest version, cobbled together from recent forum searches and help from MadDog, Strate and

Pa Callender (Thanks, by the way.). It is nearly there. It loops continuously, resume function works.

Strange intermittent problems with the cancel function. This script seems to sometimes not 'trap'

the print Job fast enough (prints anyway). Also, sometimes produces blank pages from the printer. I'm going to experiment

with the following cancel function to see if this improves things a bit. After running once the print queue icon remains in the tray, which fouls up subsequent tests with the script. I have to 'refresh' manually to fix. Could

'Auto' it, but not sure if this is the root problem.

$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\" & $strComputer & " ootcimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer Where Name = 'Local Printer ETC.'")
For $objPrinter in $colInstalledPrinters
    $objPrinter.CancelAllJobs()
Next

Ideas anyone?

Viva Autoit!!!

Thanks.....

Bubnoff

Edited 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...