-----Original Message-----
From: Chas Owens [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 01, 2006 3:25 PM
To: Ryan Frantz
Cc: Timothy Johnson; [email protected]
Subject: Re: Win32::Process::Info - Get Owner Information
>On 2/1/06, Ryan Frantz <[EMAIL PROTECTED]> wrote:
>snip
>> The script will process the first host in the list, begin processing
the
>> second host, and then perl.exe dies with a popup asking me to send
>> details to M$. I'm not very fluent with OOP, but is it possible that
>> the first object has to be destroyed before the next is created? Or
is
>> this automatic?
>>
>> BTW, I'm running ActiveState Perl 5.8.2 on WinXP SP2. The
>> Win32::Process::Info module was installed via 'ppm'.
>snip
>
>Perl has reference count garbage collection. When an object has no
>references left it is marked for recycling. The $processObj and
>@procInfo are marked as "my" or lexical variables. This means they
>will go out of scope when outside of the braces that contain them. In
>your case that would be the end of getProcInfo. When the references
>go out of scope the object's reference count gets decremented.
>
>Have you tried the "die" code I sent in an earlier email?
In this case it might not even help. If $processObj->GetProcInfo()
fails, Win32::OLE will throw an exception and end the script. Oddly
enough, even setting "Win32::OLE->Option(Warn => 0)" doesn't seem to
help, so if it was working correctly, then it would die anyway.
I tried this code, slightly rewritten:
#######################################################
use warnings;
use strict;
use Win32::Process::Info;
my @servers = ($ENV{COMPUTERNAME},"othersystem1",'othersystem');
@servers = sort @servers;
use Win32::OLE;
Win32::OLE->Option(Warn => 0);
$| = 1;
sub getProcInfo {
my $server = shift @_;
if(my $processObj = Win32::Process::Info->new( $server, 'WMI' )){
my @procInfo = $processObj->GetProcInfo();
# this should give us a list of anonymous hashes...foreach my
$info (@procInfo) {if ( ref $info ) {my $procName;
foreach my $info(@procInfo){
if ( ref $info ) {
my $procName;
my $procOwner;
$procName = ${$info}{Name};
$procOwner = ${$info}{Owner};
if ( $procName and $procOwner ) {#print "\n";
print $procName . ": " . $procOwner . "\n";
}
}else{
print "Info: $info\n";
}
}
return 1;
}else{
return 0;
}
}
foreach my $server (@servers) {
print "\n-- $server --\n";
getProcInfo($server) || print "FAILED!\n\n";
}
#########################################################
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>