Win32::Printer::Enum::Printer($server)
Win32::Printer::Enum::Printer($server)
am 23.06.2005 14:18:43 von Brian McCauley
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.
Re: Win32::Printer::Enum::Printer($server)
am 24.06.2005 12:59:32 von Sisyphus
"Brian McCauley" wrote in message
news:d9e9bm$bbs$1@redhat2.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
Re: Win32::Printer::Enum::Printer($server)
am 24.06.2005 15:15:47 von Stephen Patterson
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 steve@patter.mine.nu http://patter.mine.nu/
Linux Counter No: 142831 GPG Public key: E3E8E974
"Whoever said nothing is impossible never tried slamming a revolving door."
-- Melissa O'Brien
Re: Win32::Printer::Enum::Printer($server)
am 25.06.2005 08:47:23 von Brian McCauley
Sisyphus wrote:
> "Brian McCauley" wrote in message
> news:d9e9bm$bbs$1@redhat2.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.
Re: Win32::Printer::Enum::Printer($server)
am 27.06.2005 11:42:35 von Thomas Kratz
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,(security)}$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
--
$/=$,,$_=,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 ^.-
Re: Win32::Printer::Enum::Printer($server)
am 12.07.2005 14:12:23 von iansullivan
> 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=imperson ate,(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");
}
}
re:Win32::Printer::Enum::Printer($server)
am 12.07.2005 14:50:34 von iansullivan
I have also noted that the Status returned in Win32\Printers is
"Ready" but the script returns "Unknown".
Ho Hum . . .
Re: Win32::Printer::Enum::Printer($server)
am 13.07.2005 11:02:37 von Thomas Kratz
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
--
$/=$,,$_=,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 ^.-
Re: Win32::Printer::Enum::Printer($server)
am 13.07.2005 11:05:49 von Thomas Kratz
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
http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/wmisdk/wmi/win32_printer.asp
Thomas
--
$/=$,,$_=,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 ^.-
Re: Win32::Printer::Enum::Printer($server)
am 13.07.2005 11:12:52 von Thomas Kratz
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=imperson ate,(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
--
$/=$,,$_=,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 ^.-
Re: Win32::Printer::Enum::Printer($server)
am 19.07.2005 17:44:08 von iansullivan
> 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