Creating objects

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
 
J

James Willmore

On 26 Aug 2003 06:02:13 -0700
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.

Define what you mean by "silly". I'm of the opinion that, if it's
going to aid in producing code latter on, then it's not "silly" - it's
smart. It's that OO thing again.

Other may have opinions on this, but that's mine to offer.
 
B

brice

James Willmore said:
Define what you mean by "silly". I'm of the opinion that, if it's
going to aid in producing code latter on, then it's not "silly" - it's
smart. It's that OO thing again.

Other may have opinions on this, but that's mine to offer.

Thanks for your response, I feel the same way. I know this will help
me in the future grabbing this information from my Windows boxes.

brice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top