Necos has asked for the wisdom of the Perl Monks concerning the following question:

I know that you can monitor resources (disk, etc.) from Perl. One thing that I've noticed is that none of the resource monitoring modules/scripts/etc. don't have options for monitoring printer queues. Is there some way to hack together a module to monitor print queues and their attributes? I've been looking at the Win32::Perf library, but, again, I didn't see anything that had to do with the printer queues. I (of course) have been unable to come across any information that discusses the WindowsNT printing structure (I only know what I've read in the primers and beginning WinNT books). Personally, I think a blocking routine in Perl (similar to the RPC.pm module from Advanced Perl Programming) would be a perfect utility to monitor printer queues, mainly because it doesn't block for very long. If you need to block longer (possibly to read and possibly identify the data going to print), Perl, again provides a nice setup to allow for variable blocking times. Any tips/hints/leads/etc. would be greatly appreciated.

Necos
secon_kun@hotmail.com

Replies are listed 'Best First'.
Re: WinNT Printer monitoring...
by idnopheq (Chaplain) on Sep 05, 2001 at 14:41 UTC
    Check out PortMon from SysInternals. While not a perl answer, it can do remote queries of machines.

    Dig a bit on their site. They have all kinds of interesting little bits of information about Win32 systems ...

    UPDATE: should one choose to write a module for this, a reference is Printing and Print Spooler Functions from http://msdn.microsoft.com.

    UPDATE: I think I found the Win32::OLE lib and properies for this ... check out oleprn 1.0 Type Library in your Win32::OLE::Browser, asphelp and PrtSum.

    HTH
    --
    idnopheq
    Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.

Re: WinNT Printer monitoring...
by rchiav (Deacon) on Sep 05, 2001 at 15:52 UTC
    It's funny that you should ask this. I'm currently working on a Perl program that will allow somone to administer printers. When done, it will work for NT and Novell without having to install the driver or map to the printer.

    What I'm using (and what you're going to want to look at) is ADSI. Specifically, look at this page. Scroll down till you see IADsPrintQueue and IADsPrintQueueOperations. You'll use Win32::OLE to access these.

    Let me know if you need an example and I'll throw one together.

    Hope this helps..
    Rich

      ASDI seems like a nice option. However, that means upgrading my domain to Active Directory (to be able to access the API), which I don't really trust. I know Microsoft has done a lot to AD since the launch of WinNT 5, but it's not something I want to bet my car and college on. I'd be a little more interested in a Win32::API(EnumPrinters()) call (I just got a chance to look at the MSDN Printer reference that was pointed out). This would be a much nicer thing to do (albeit possibly slower) since it would be backwards compatible (I have a thing for backwards compatibility). Maybe I'm just being harsh on Active Directory, but oh well. Thanks for the lead though. It's definitely worth a shot.

      Necos
      secon_kun@hotmail.com
        No, you don't have to upgrade to 2000. There's the "WinNT://" service providor which works just fine for NT machines. That link I gave you includes what objects are available to which service providors. You can even interface the entire Novell NDS structure (OU's, users, printers, etc..)

        Here's a little sample. This will list the names of printers on a praticular NT server..

        !/usr/bin/perl -w use strict; use Win32::OLE qw/in/; #fill in domain and server my $domain = ''; my $server = ''; my $printer; my $objServer = Win32::OLE->GetObject("WinNT://$domain/$server"); $objServer->{FILTER} = ["printqueue"]; foreach $printer (in $objServer) { print "$printer->{NAME}\n"; }
        Hope this helps..
        Rich
Re: WinNT Printer monitoring...
by MZSanford (Curate) on Sep 05, 2001 at 13:10 UTC
    When i see windows interaction and 'hack together', i think Win32::API. The module will load a DLL file, and let you use functions from it (but you need to know the functions and arguments). I am not sure the DLL, but that would be my first guess..
    can't sleep clowns will eat me
    -- MZSanford