Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I recently went through a similiar process, however I also needed to know if it was a specifically named printer, and the form type loaded in the printer. I ended up writing a daemon that runs on the NT systems with a socket interface. My perl script on the Linux box connects to the daemon and can issue commands to request a list of attached printers, determine the form type, etc.

Printers can be attached several different ways: as a local connection (LPT or COM on the back of the PC), a share to a remote server (such as NT), and a share to a non-server (such as a printer on a Win95/98 box). Depending on where the printer is attached will determine where it will show up in the registry. Start by looking at HKEY_LOCAL_MACHINE | SYSTEM | CurrentControlSet | Control | Print | Printers. There is where the shares that the NT box has to the Win95 shares. Look in ... | Control | Print | Providers | LanMan Print Services for the others. You'll see the same printers that are in the previous leaf there, but the only information is where the spool directory is.

One of the problems is determining how the keys are to be interpeted. Some are meant to be used by the print spoolers within NT, and some are meant to be used by the print driver. I never did figure out exactly how NT enumerated the printers that show up when you click Start | Settings | Printers.

What my daemon ended up doing was using the EnumPrinters API call, with PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS as flags. I then look for the printer name I specifically need in the name of the printer that's returned. If someone has renamed the printer, then I'm hosed.

I can e-mail you the source for the daemon if you like (, but you'll need VisualStudio to compile it.

I spent a lot of time hacking the registry and cruising MSDN, trying to avoid writing something using the printer API. It can stall for a short time if the printer that the connection in your Printers folder is supposed to be connected to isn't there (someone turns the machine off, whatever).

I feel like what I did was a compromise, but it does work. 'Course, if we had a real network that wasn't polluted with NetBUI, and everyone had TCP/IP installed, it might be a different matter.

Sorry I can't be of more help. Maybe this, combined with some other elightened soul out here can get a solution that's reliable.


Oh yea, when using the registry, you may have to be concerned about whether any of the connections are 'dead' printers or not (points to a no-longer existent printer). If this is the case, and you try to talk to it, you may end up hanging, or worse yet, generating a system dialog box that your perl script can't do anything about. This is one of the reasons that I took the approach I did. When you interrogate the printer for their forms data, there are certain flags that specify the amount of information returned by the API call. If you pick the wrong ones, you can end up with system dialog boxes, or taking an incredibly long time to figure out the printer isn't really there.

In reply to (jcwren) Re: Printers (NT) by jcwren
in thread Printers (NT) by Kevman

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (3)
    As of 2018-03-24 01:10 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (297 votes). Check out past polls.