Ask a Question related to PERL Modules, Design and Development.
-
Brian McCauley #1
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
-
print to network printer using ASP.NET on IIS6 (2003 Server)
Is there any security reason why you cannot print to a network printer from ASP.NET under IIS6 on Windows 2003 server? I'm using ASP.NET code to... -
Backup Printer Server
I have one of my servers performing the print server role. I would like to setup an additional server to act as a backup printer server in the... -
Windows Server 2003 / printer driver fpr LaserJet 3100
has anybody a idea where I can get a printer driver for my LaserJet 3100 and the Windows Server 2003. The XP driver doesn't work and on the HP... -
Printer addition on XP from 2000 server
Why would some clients, that have local admin rights, not be able to add printer from WIN2K server. Print spooler is started on both. They were... -
Print Server For OS 9, OS X, and Windows with USB Printer?
On Thu, 17 Jul 2003 20:27:51 GMT, <JHawkins@HumanitiesSoftware.Com> wrote: http://iharder.sourceforge.net/macosx/winmacprinter/#step2 It's a... -
Sisyphus #2
Re: Win32::Printer::Enum::Printer($server)
"Brian McCauley" <nobull@mail.com> wrote in message
news:d9e9bm$bbs$1@redhat2.bham.ac.uk...Can't help a lot, if at all - I don't have a printer. (If you get stuck you> 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.
>
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
-
Stephen Patterson #3
Re: Win32::Printer::Enum::Printer($server)
On Thu, 23 Jun 2005 13:18:43 +0100, Brian McCauley wrote:
If you can connect to a remote registry from perl, then this code may> Has anyone ever managed to get Win32::Printer::Enum::Printer($server) to
> enumerate printers on a server?
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]steve@patter.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
-
nobull@mail.com #4
Re: Win32::Printer::Enum::Printer($server)
Sisyphus wrote:> "Brian McCauley" <nobull@mail.com> 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.)Thanks for that - I may try that later. In the short term I've solved> 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()}";
> }
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
-
Thomas Kratz #5
Re: Win32::Printer::Enum::Printer($server)
Brian McCauley wrote:
I tend to use WMI these days. You might want to try this:> Has anyone ever managed to get Win32::Printer::Enum::Printer($server) to
> enumerate printers on a server?
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
-
Sully #6
Re: Win32::Printer::Enum::Printer($server)
> Thomas Kratzwrote:
Thomas,>
> I tend to use WMI these days. You might want to try this:
> .
> .
> .
> .
>
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
-
Sully #7
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
-
Thomas Kratz #8
Re: Win32::Printer::Enum::Printer($server)
Sully wrote:
The headers are printed by the first 'print'.>>>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.
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
-
Thomas Kratz #9
Re: Win32::Printer::Enum::Printer($server)
Sully wrote:
Yep, the 'Status' field exists but is not filled by WMI. Please use the> I have also noted that the Status returned in Win32\Printers is
> "Ready" but the script returns "Unknown".
>
> Ho Hum . . .
>
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
-
Thomas Kratz #10
Re: Win32::Printer::Enum::Printer($server)
Sully wrote:
Aah! I had to read this a few times before I realized what you mean. You> 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. .
have lost all indentation in your reply
No @attrib contains the headings. What you want is the actual parameter of> .
>
> 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)
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
-
Sully #11
Re: Win32::Printer::Enum::Printer($server)
> Thomas Kratzwrote:
Sully wrote:You>
>
> Aah! I had to read this a few times before I realized what you mean.> 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



Reply With Quote

