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,(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


-- $/=$,,$_=<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^.- .