Professional Web Applications Themes

Win32::Printer::Enum::Printer($server) - PERL Modules

Has anyone ever managed to get Win32::Printer::Enum::Printer($server) to enumerate printers on a server? I've tried $server with a plain server name e.g. "MYBOX" and "\\MYBOX" nither give any response. (Note I'm using an accound with Administrator priv at MYBOX). Looking at MSDN it implies that the parameter to EnumPrinters() should be "Print Provider!!\Machine" so I tried "win32spl.dll!!\\MYBOX" and "win32spl!!\\MYBOX" and "LanMan Print Services!!\\MYBOX" Still Win32::Printer::Enum::Printer() stubbonly returns nothing....

  1. #1

    Default Win32::Printer::Enum::Printer($server)

    Has anyone ever managed to get Win32::Printer::Enum::Printer($server) to
    enumerate printers on a server?

    I've tried $server with a plain server name e.g. "MYBOX" and "\\\\MYBOX"
    nither give any response. (Note I'm using an accound with Administrator
    priv at MYBOX).

    Looking at MSDN it implies that the parameter to EnumPrinters() should
    be "Print Provider!!\\Machine" so I tried

    "win32spl.dll!!\\\\MYBOX"

    and

    "win32spl!!\\\\MYBOX"

    and

    "LanMan Print Services!!\\\\MYBOX"

    Still Win32::Printer::Enum::Printer() stubbonly returns nothing.

    Brian McCauley Guest

  2. #2

    Default Re: Win32::Printer::Enum::Printer($server)


    "Brian McCauley" <nobullmail.com> wrote in message
    news:d9e9bm$bbs$1redhat2.bham.ac.uk...
    > Has anyone ever managed to get Win32::Printer::Enum::Printer($server) to
    > enumerate printers on a server?
    >
    > I've tried $server with a plain server name e.g. "MYBOX" and "\\\\MYBOX"
    > nither give any response. (Note I'm using an accound with Administrator
    > priv at MYBOX).
    >
    > Looking at MSDN it implies that the parameter to EnumPrinters() should
    > be "Print Provider!!\\Machine" so I tried
    >
    > "win32spl.dll!!\\\\MYBOX"
    >
    > and
    >
    > "win32spl!!\\\\MYBOX"
    >
    > and
    >
    > "LanMan Print Services!!\\\\MYBOX"
    >
    > Still Win32::Printer::Enum::Printer() stubbonly returns nothing.
    >
    Can't help a lot, if at all - I don't have a printer. (If you get stuck you
    might find some help on ActiveState's perl-win32-users list.)

    In the Printers() function I see the following code:

    my $return = Win32::Printer::_EnumPrinters($flag, $server);
    unless (defined($return))
    {croak "ERROR: Cannot enumerate printers!
    ${\Win32::Printer::_GetLastError()}";
    }

    That code seems a bit suss to me. If I call it as 'Printers("rubbish");', I
    too find that it runs without output, though, of course, the domain named
    "rubbish" doesn't even exist. I suspect that '(defined($return))' should be
    replaced simply with '($return)'.
    If EnumPrinters() fails, I think that _EnumPrinters() still returns a
    defined (but untrue) value.

    Anyway, you might find it useful to replace the above code with:

    my $return = Win32::Printer::_EnumPrinters($flag, $server);
    unless ($return)
    {croak "$flag : $server: ERROR: Cannot enumerate printers!
    ${\Win32::Printer::_GetLastError()}";
    }

    With that change I get:

    8 : \\rubbish : ERROR: Cannot enumerate printers! The RPC server is
    unavailable.
    at try.pl line 5

    which looks sane to me.

    Hth.

    Cheers,
    Rob



    Sisyphus Guest

  3. #3

    Default Re: Win32::Printer::Enum::Printer($server)

    On Thu, 23 Jun 2005 13:18:43 +0100, Brian McCauley wrote:
    > Has anyone ever managed to get Win32::Printer::Enum::Printer($server) to
    > enumerate printers on a server?
    If you can connect to a remote registry from perl, then this code may
    work (it works fine with local printers).

    sub list_printers {
    # list available printers
    my %printers;

    # look at registry to get printer names for local machine
    my $Register = 'SYSTEM\CurrentControlSet\Control\Print\Printers';
    my ($hkey, key_list, names, ports);
    my $HKEY_LOCAL_MACHINE = $main::HKEY_LOCAL_MACHINE;
    $HKEY_LOCAL_MACHINE->Open($Register, $hkey) or
    Carp::croak "Can't open registry key HKEY_LOCAL_MACHINE\\$Register: $!";
    $hkey->GetKeys(\key_list);
    foreach my $key (key_list) {
    my $path = $Register . '\\' . $key;
    my ($pkey, %values, $printers);
    $HKEY_LOCAL_MACHINE->Open($path, $pkey) or
    Carp::croak "Can't open registry key HKEY_LOCAL_MACHINE\\$path: $!";
    $pkey->GetValues(\%values);
    push ports, $values{Port}[2];
    push names, $values{Name}[2];
    }
    $printers{name} = [ names ];
    $printers{port} = [ ports ];
    return %printers;
    }


    --
    Stephen Patterson [email]stevepatter.mine.nu[/email] [url]http://patter.mine.nu/[/url]
    Linux Counter No: 142831 GPG Public key: E3E8E974
    "Whoever said nothing is impossible never tried slamming a revolving door."
    -- Melissa O'Brien
    Stephen Patterson Guest

  4. #4

    Default Re: Win32::Printer::Enum::Printer($server)



    Sisyphus wrote:
    > "Brian McCauley" <nobullmail.com> wrote in message
    > news:d9e9bm$bbs$1redhat2.bham.ac.uk...
    > >
    > > ... Win32::Printer::Enum::Printer() stubbonly returns nothing.
    > >
    >
    > Can't help a lot, if at all - I don't have a printer. (If you get stuck you
    > might find some help on ActiveState's perl-win32-users list.)
    > Anyway, you might find it useful to replace the above code with:
    >
    > my $return = Win32::Printer::_EnumPrinters($flag, $server);
    > unless ($return)
    > {croak "$flag : $server: ERROR: Cannot enumerate printers!
    > ${\Win32::Printer::_GetLastError()}";
    > }
    Thanks for that - I may try that later. In the short term I've solved
    my immediate problem by parsing a REGEDIT export.

    Thanks also to Stephen Patterson - if I need to automate this process I
    may use the registry modules but the registry layout is not so simple
    because the server is actually a virtual server in a cluster config.

    nobull@mail.com Guest

  5. #5

    Default Re: Win32::Printer::Enum::Printer($server)

    Brian McCauley wrote:
    > Has anyone ever managed to get Win32::Printer::Enum::Printer($server) to
    > enumerate printers on a server?
    I tend to use WMI these days. You might want to try this:

    use strict;
    use warnings;

    use Win32::OLE qw/in/;
    Win32::OLE->Option(Warn => 1);

    $ARGV[0] ||= '';

    my $wmi = Win32::OLE->GetObject(
    "winmgmts:{impersonationLevel=impersonate,(securit y)}$ARGV[0]"
    ) or die
    "error initializing WMI interface, ",
    Win32::OLE->LastError;

    my attrib = qw/DeviceID Name DriverName Location Comment/;
    print join(', ', attrib), "\n";
    for my $p ( in($wmi->InstancesOf('Win32_Printer')) ) {
    $_ ||= '' for $p{attrib};
    print join(', ', $p{attrib}), "\n";
    }

    Thomas


    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
    Thomas Kratz Guest

  6. #6

    Default Re: Win32::Printer::Enum::Printer($server)

    > Thomas Kratzwrote:
    >
    > I tend to use WMI these days. You might want to try this:
    > .
    > .
    > .
    > .
    >
    Thomas,

    I am trying to adjust your code, which I think will solve my problem
    (Thanks, I was going crazy!) but I am a little lost as to how I might
    adjust it to email me if one of the queues error.

    the $attrib returns the column heading rather than the data from the
    array.

    I'm sure I am missing something simple but my brain has overheated. .
    ..

    Here is what I have so far:

    #use strict;
    use warnings;

    use Win32::OLE qw/in/;
    Win32::OLE->Option(Warn => 1);

    $ARGV[0] ||= '';

    my $wmi =
    Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersona te,(security)}$ARGV[0]")
    or die "error initializing WMI interface, ",

    Win32::OLE->LastError;

    my attrib = qw/DeviceID Status/;

    print join(', ', attrib), "\n";
    for my $p ( in($wmi->InstancesOf('Win32_Printer')) ) {
    $_ ||= '' for $p{attrib};
    print join(', ', $p{attrib}), "\n";

    if($attrib[1] ne Error)

    {
    # system("D:/\\server/share/\\dir/\\frmsendmail.exe blank\.txt -t
    me\mine.com -priority 1 -subject a_printer_has _a_problem");
    }

    }

    Sully Guest

  7. #7

    Default re:Win32::Printer::Enum::Printer($server)

    I have also noted that the Status returned in Win32\Printers is
    "Ready" but the script returns "Unknown".

    Ho Hum . . .

    Sully Guest

  8. #8

    Default Re: Win32::Printer::Enum::Printer($server)

    Sully wrote:
    >>Thomas Kratzwrote:
    >
    >
    >>I tend to use WMI these days. You might want to try this:
    >>.
    >>.
    >>.
    >>.
    >>
    >
    >
    > Thomas,
    >
    > I am trying to adjust your code, which I think will solve my problem
    > (Thanks, I was going crazy!) but I am a little lost as to how I might
    > adjust it to email me if one of the queues error.
    >
    > the $attrib returns the column heading rather than the data from the
    > array.
    The headers are printed by the first 'print'.
    One line of values is printed for each printer of the computer you specify
    on the command line like

    perl script.pl \\MYSERVER

    Thomas

    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
    Thomas Kratz Guest

  9. #9

    Default Re: Win32::Printer::Enum::Printer($server)

    Sully wrote:
    > I have also noted that the Status returned in Win32\Printers is
    > "Ready" but the script returns "Unknown".
    >
    > Ho Hum . . .
    >
    Yep, the 'Status' field exists but is not filled by WMI. Please use the
    WMI Browser from M$ to look for values with meaningful content (WMI is
    still 'work in progress in many places').
    You can use 'PrinterStatus' wich contains an uint16. You can lookup the
    values in

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp[/url]

    Thomas

    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
    Thomas Kratz Guest

  10. #10

    Default Re: Win32::Printer::Enum::Printer($server)

    Sully wrote:
    > the $attrib returns the column heading rather than the data from the
    > array.
    >
    > I'm sure I am missing something simple but my brain has overheated. .
    Aah! I had to read this a few times before I realized what you mean. You
    have lost all indentation in your reply
    > .
    >
    > Here is what I have so far:
    >
    > #use strict;
    > use warnings;
    >
    > use Win32::OLE qw/in/;
    > Win32::OLE->Option(Warn => 1);
    >
    > $ARGV[0] ||= '';
    >
    > my $wmi =
    > Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersona te,(security)}$ARGV[0]")
    > or die "error initializing WMI interface, ",
    >
    > Win32::OLE->LastError;
    >
    > my attrib = qw/DeviceID Status/;
    >
    > print join(', ', attrib), "\n";
    > for my $p ( in($wmi->InstancesOf('Win32_Printer')) ) {
    > $_ ||= '' for $p{attrib};
    > print join(', ', $p{attrib}), "\n";
    >
    > if($attrib[1] ne Error)
    No attrib contains the headings. What you want is the actual parameter of
    the hash referenced by $p. Also ITYM 'eq' instead of 'ne'.

    if ( $p->{Status} eq 'Error' )

    But then as you have noticed, the 'Status' parameter doesn't do what you
    want (see my other response)
    >
    > {
    > # system("D:/\\server/share/\\dir/\\frmsendmail.exe blank\.txt -t
    > me\mine.com -priority 1 -subject a_printer_has _a_problem");
    > }
    >
    > }
    >

    Thomas

    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e. r^.>l^..>k^.-
    Thomas Kratz Guest

  11. #11

    Default Re: Win32::Printer::Enum::Printer($server)

    > Thomas Kratzwrote:
    Sully wrote:
    >
    >
    > Aah! I had to read this a few times before I realized what you mean.
    You
    > have lost all indentation in your reply
    >
    >

    Thanks Thomas, your comments have now let me complete my code.

    Thanks for all of your help!

    Sully

    Sully Guest

Similar Threads

  1. Replies: 1
    Last Post: April 29th, 02:28 PM
  2. Backup Printer Server
    By Bob Hess in forum Windows Server
    Replies: 1
    Last Post: July 2nd, 03:57 PM
  3. Printer addition on XP from 2000 server
    By KJ in forum Windows Server
    Replies: 1
    Last Post: June 3rd, 07:53 PM
  4. Print rendered .aspx page to server's printer
    By Robin Dindayal in forum ASP.NET General
    Replies: 1
    Last Post: July 24th, 11:59 PM
  5. Print Server For OS 9, OS X, and Windows with USB Printer?
    By foo in forum Mac Applications & Software
    Replies: 3
    Last Post: July 18th, 06:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139