B
brice
Hello,
I am using Perl to access the Windows management interface to query
information on some Windows boxes through the Win32::OLE module. I am
on Windows 2000 Professional SP4 using ActivePerl 5.8. I wanted to
create a cleaner interface to this information by trying the following
code:
# ****************************************
# PACKAGE
# ****************************************
package WMI;
use Win32::OLE qw(in);
sub new{
my $host = @_[1];
my $WMI = Win32::OLE->GetObject("winmgmts://$host");
my $class = shift;
my $self = { WMI => $WMI };
bless($self, $class);
return $self;
}
sub getServices{
my $self = shift;
my $WMI = $self->{WMI};
my $set = $WMI->InstancesOf("Win32_Service");
foreach(in($set)){
print "$_->{Name}\n";
}
}
1;
# ***********************************************
# ***********************************************
# Sample Code which successfully prints out a list of running
services.
# ***********************************************
#!C:/perl/bin/perl
use strict;
use WMI;
my $WMI = WMI->new("localhost");
$WMI->getServices();
# ************************************************
So my question now is, is this a silly way to do this by taking an
object and creating another layer over it like I've done? Your
comments are greatly appreciated.
Thanks,
brice
I am using Perl to access the Windows management interface to query
information on some Windows boxes through the Win32::OLE module. I am
on Windows 2000 Professional SP4 using ActivePerl 5.8. I wanted to
create a cleaner interface to this information by trying the following
code:
# ****************************************
# PACKAGE
# ****************************************
package WMI;
use Win32::OLE qw(in);
sub new{
my $host = @_[1];
my $WMI = Win32::OLE->GetObject("winmgmts://$host");
my $class = shift;
my $self = { WMI => $WMI };
bless($self, $class);
return $self;
}
sub getServices{
my $self = shift;
my $WMI = $self->{WMI};
my $set = $WMI->InstancesOf("Win32_Service");
foreach(in($set)){
print "$_->{Name}\n";
}
}
1;
# ***********************************************
# ***********************************************
# Sample Code which successfully prints out a list of running
services.
# ***********************************************
#!C:/perl/bin/perl
use strict;
use WMI;
my $WMI = WMI->new("localhost");
$WMI->getServices();
# ************************************************
So my question now is, is this a silly way to do this by taking an
object and creating another layer over it like I've done? Your
comments are greatly appreciated.
Thanks,
brice