Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Getting a Local/Remote Win32 Task List

by gaggio (Friar)
on Jul 05, 2000 at 03:10 UTC ( [id://21069]=CUFP: print w/replies, xml ) Need Help??

Here a function to list all the processes running on a machine. It uses Win32::Perflib.
The function returns a pid-indexed hash with all the tasks running on a Win32 machine, as listed in the task manager.
You'll notice, that the function takes the machine you want to monitor as an argument: it is possible to get the task list of a remote machine.
It can be used as the first part of a program to fully remote control a Win32 machine (you will probably need to use Win32::Process to kill programs, and implement some sort of client server protocol also, a very tiny job for a Perl Monk :-)
sub get_remote_process_list { my $server = $_[0]; my %rtasks; my %counter; Win32::PerfLib::GetCounterNames($server, \%counter); my %r_counter = map { $counter{$_} => $_ } keys %counter; # retrieve the id for process object my $process_obj = $r_counter{Process}; # retrieve the id for the process ID counter my $process_id = $r_counter{'ID Process'}; # create connection to $server my $perflib = new Win32::PerfLib($server); my $proc_ref = {}; # get the performance data for the process object $perflib->GetObjectList($process_obj, $proc_ref); $perflib->Close(); my $instance_ref = $proc_ref->{Objects}->{$process_obj}->{Instances}; foreach my $p (sort keys %{$instance_ref}) { my $counter_ref = $instance_ref->{$p}->{Counters}; foreach my $i (keys %{$counter_ref}) { if($counter_ref->{$i}->{CounterNameTitleIndex} == $process_id) { $rtasks{$counter_ref->{$i}->{Counter}} = $instance_ref->{$ +p}->{Name}; } } } return %rtasks; }

Replies are listed 'Best First'.
RE: Getting a Local/Remote Win32 Task List
by Adam (Vicar) on Jul 06, 2000 at 00:38 UTC
    Having not used Win32::PerfLib before, I am curious about this snippet of code, but I don't quite understand what I need to pass in for $server. Are you looking for the IP? Or a machine name? or something else? Thanks.

    -Adam

      You can pass either (machine name or IP). Try it, it is working here (I litteraly did a "cut-and-paste" from within my NT remote controlling project - yes, I actually wrote one).
        gaggio, i tried using your little tidbit and it is awesome. you rock! Being a beginner in perl, i was wondering if you know how to format the info displayed from the remote tlist? Thanks in advance. Ray
      I'm getting: Can't call method "GetObjectList" on an undefined value at RasUpload.pl line 68. when using your sub and I have no idea why....any ideas? doofie_dee@yahoo.com
        i'm getting the same error. find anything out?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://21069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-10-10 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (45 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.