Sign in to follow this  
Followers 0

Printer Management....with guilt trip script.

1 post in this topic

#1 ·  Posted (edited)

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
    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
                $msg = MsgBox (17, "Print Notification",$objPrintJob.TargetInstance.Document)
                    If $msg = 1 Then _resume()
                    If $msg = 2 Then _cancel()
    Func _resume()
    Func _cancel()
        SplashTextOn("", "Stopping Print Spooler, please wait...", 150, 75)
        _RunDOS("NET STOP spooler")
        SplashTextOn("", "Clearing print job, please wait...", 150, 75)
        FileDelete(@SystemDir & "\spool\PRINTERS\*.*")
        SplashTextOn("", "Starting Print Spooler, please wait...", 150, 75)
        _RunDOS("NET START spooler")
        MsgBox(64, "Done!", "Done", 3)

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

Ideas anyone?

Viva Autoit!!!



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