Here's a chunk of code that I wrote (with the help of someone else on this
list) which will return the number of pids matching a given program name.  A
better perl programmer than myself could modify this to just examine a list
of all processes.  ;-)

############################################################################
####
# getPidList:
# Gets a list of pids matching a given application.  Requires a program name
(eg. calc.exe)
# and an array reference as its arguments.
# Usage:
# getPidList ( $sAppName, \@lPidList );
# Returns:
# This subroutine returns as its return code the number of matches for the
given 
# application name, or 0 (false) if no matches are found.
############################################################################
####
sub getPidList {

  my ($sAppName, $lPidList) = @_;

  my $iCtr = 0;
  my $iPid;
  my $sDesc;
  my $Server;

  use Win32::OLE qw( in );

  my $CLASS =
  "winmgmts:{impersonationLevel=impersonate}$Server\\Root\\cimv2";
  my $WMI = Win32::OLE->GetObject( $CLASS ) || die Win32::FormatMessage(
Win32::GetLastError() );

  foreach my $Proc ( sort {lc $a->{Name} cmp lc $b->{Name}} in(
$WMI->InstancesOf( "Win32_Process" ) ) )
  {
    $iPid = $Proc->{'ProcessID'}; 
    $sDesc = $Proc->{'Description'}; 
    if ( $sDesc =~ /$sAppName/i ) {
      @$lPidList[$iCtr] = $iPid;
      $iCtr++;
    }
  }
  return $iCtr;
}

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:extern.Lars.Oeschey@;audi.de]
Sent: Monday, October 21, 2002 3:54 AM
To: [EMAIL PROTECTED]
Subject: Active processes


Hi,

I couldn't find this in AdminMisc, is there a way to see what processes are
active? Is there also a way for Win9x clients?

Mit freundlichen Gr��en,

Lars Oeschey
CAT Systemintegration

Audi AG
I/EK-66, extern
Tel./Audi  +49 (0)841 89-30450
mailto:extern.lars.oeschey@;audi.de 
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to