Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi fellas. how can I access the list of the processes running on a NT station thanks to a perl script ? I've noticed the Win32::Process module, yet it has no method designed to do so. PLEASE HELP !

Replies are listed 'Best First'.
Re: List NT processes using perl scripts
by strat (Canon) on Jan 22, 2002 at 17:15 UTC
    There are several possibilities, e.g.
    #!perl -w use strict; use Win32::OLE qw(in); #Mode: Window Management Instrumentation (WMI) # processproperties my @properties = qw(Caption CreationClassName CreationDate CSCreationC +lassName CSName Description ExecutablePath ExecutionState Handle HandleCount InstallDate KernelModeTime MaximumWorkingSetSi +ze MinimumWorkingSetSize Name OSCreationClassName OSName OtherOperationCount OtherTransferCount PageFaults PageFile +Usage ParentProcessId PeakPageFileUsage PeakVirtualSize PeakWork +ingSetSize Priority PrivatePageCount ProcessId QuotaNonPagedPoolUsage QuotaPagedPoolUsage QuotaPeakNonPagedPoolUsage QuotaPeakPa +gedPoolUsage ReadOperationCount ReadTransferCount SessionId Status Term +inationDate ThreadCount UserModeTime VirtualSize WindowsVersion Workin +gSetSize WriteOperationCount WriteTransferCount); # processmethods my @methods = qw(Create Terminate GetOwner GetOwnerSid); my $server = ''; # local machine my $locatorObj = Win32::OLE->new('WbemScripting.SWbemLocator') or die ("Error in creating locator object: ".Win32::OLE->LastError +()."\n"); $locatorObj->{Security_}->{impersonationlevel} = 3; my $serverObj = $locatorObj->ConnectServer($server, 'root\cimv2') or die ("Error in creating server object: ".Win32::OLE->LastError( +)."\n"); my $procSchema = $serverObj->Get('Win32_Process'); #@properties = map{ $_->{Name} } (in $procSchema->{Properties_}); #@methods = map{ $_->{Name} } (in $procSchema->{Methods_}); foreach my $process (in $serverObj->InstancesOf("Win32_Process")){ foreach (@properties){ printf ("'%20s' => '%s'\n", $_, $process->{$_} || '' ); } print ("-----------------------------------------------\n"); }

    Best regards,
    perl -e "print a|r,p|d=>b|p=>chr 3**2 .7=>t and t"

Retrieving Win32 Process list (boo)
by boo_radley (Parson) on Jan 22, 2002 at 19:37 UTC
    I would use the little advertised module Win32::Setupsup.
    use Win32::Setupsup; die if(!Win32::Setupsup::GetProcessList('', \@proc, \@threads)); foreach $item (@proc) { print "name: ${$item}{'name'}; pid: ${$item}{'pid'}\n";} foreach $item (@threads) { print "tid: ${$item}{'tid'}; pidx: ${$item}{'process'}; process: + ${$proc[${$item}{'process'}]}{'name'}\n"; }
Re: List NT processes using perl scripts
by t0mas (Priest) on Jan 22, 2002 at 19:35 UTC
    I wrote a small module to do just this, using Win32::API, a long time ago :-)

    Posted it here at: Win32SnapWalk


    /brother t0mas
Re: List NT processes using perl scripts
by strat (Canon) on Feb 01, 2002 at 13:51 UTC
    By the way: in NT-Reskit, there is a small exe called tlist.exe. With this, you can also find out which tasks are already running. Some years ago (1999?), I used it for finding out which processes were running on a Metaframe (for a licencing tool), and sometime it just hung (propably because of multiuser). Then I used the OLE-Trick I posted in my first message, and now everything is fine.

    Best regards,
    perl -e "$_=*F=>y~\*martinF~stronat~=>s~<[^\w]~~g=>chop,print"