in reply to WIN32 calls
Here a function to list all the processes running on a machine. It uses Win32::Perflib.
Maybe that I did not quite get the purpose of your program, though. Do you want to list only the services running or the tasks? This function returns a pid-indexed hash with all the tasks running on a Win32 machine, as listed in the task manager.
You'll notice, BTW, 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. I just decided to publish this function in the Snippets Section also, since it can be useful to somebody else.
If you want to have your perl script run as a service, you might want to use Win32::Daemon from Roth.net. I have used the module and found it very useful.
Maybe that I did not quite get the purpose of your program, though. Do you want to list only the services running or the tasks? This function returns a pid-indexed hash with all the tasks running on a Win32 machine, as listed in the task manager.
You'll notice, BTW, 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. I just decided to publish this function in the Snippets Section also, since it can be useful to somebody else.
If you want to have your perl script run as a service, you might want to use Win32::Daemon from Roth.net. I have used the module and found it very useful.
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: Re: WIN32 calls
by kapper (Chaplain) on Jul 05, 2000 at 11:57 UTC | |
by t0mas (Priest) on Jul 05, 2000 at 13:55 UTC | |
by gaggio (Friar) on Jul 05, 2000 at 17:31 UTC | |
by t0mas (Priest) on Jul 06, 2000 at 00:36 UTC |
In Section
Seekers of Perl Wisdom