Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Get Windows Task-Names?! (http://www.velocityreviews.com/forums/t883380-get-windows-task-names.html)

Kasper Dziurdz 10-31-2003 12:22 PM

Get Windows Task-Names?!
 
Hi,

is there a way or module to get the names of Windows tasks currently
running (for example "Google - Mozilla" but not "mozilla.exe")?!

Thanks,

Kasper

--
HTML::KTemplate | Perl module to process HTML templates.
http://search.cpan.org/dist/HTML-KTemplate/

Kopierschutz-Nein-Danke.de | Gegen kopiergeschützte Un-CDs!
http://www.kopierschutz-nein-danke.de/


James Willmore 10-31-2003 04:24 PM

Re: Get Windows Task-Names?!
 
On Fri, 31 Oct 2003 13:22:07 +0100
Kasper Dziurdz <usenet@repsak.de> wrote:
> is there a way or module to get the names of Windows tasks currently
>
> running (for example "Google - Mozilla" but not "mozilla.exe")?!


I'm not 100% sure about this, but you could look at one of the many
Win32 modules. I'm thinking one of those modules will accomplish the
task.

A quick glance at:
http://search.cpan.org/search?query=...ss&mode=module

shows Win32::Process::Info and Win32API::ProcessStatus _may_ fit the
bill.

One suggestion is to find out how to do what you want to do at the
command line and then fashion a script around that command.

I'm not a very big Windows user, so these are just suggestions.
Others may be more helpful.

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
When we are planning for posterity, we ought to remember that
virtue is not hereditary. -- Thomas Paine

Kasper Dziurdz 11-01-2003 11:31 AM

Re: Get Windows Task-Names?!
 
Thanks for the information! The only problem is, I never programmed in
C. I thought about using Win32::API and searched the MSDN but I did not
find what I was looking for (perhaps I have to search again).
Win32::ToolHelp seems to be good enough but returns only the processes
name like "mozilla.exe" and not "Google - Mozilla". Same with other
modules I found on CPAN.

Kasper

--
HTML::KTemplate | Perl module to process HTML templates.
http://search.cpan.org/dist/HTML-KTemplate/

Kopierschutz-Nein-Danke.de | Gegen kopiergeschützte Un-CDs!
http://www.kopierschutz-nein-danke.de/


Kasper Dziurdz 11-01-2003 02:56 PM

Re: Get Windows Task-Names?!
 
I got a solution and it is easier than I thought :-)

@tasks = split "\n", `tasklist.exe /v`;
@tasks = @tasks[3..$#tasks];

Kasper

--
HTML::KTemplate | Perl module to process HTML templates.
http://search.cpan.org/dist/HTML-KTemplate/

Kopierschutz-Nein-Danke.de | Gegen kopiergeschützte Un-CDs!
http://www.kopierschutz-nein-danke.de/


Kasper Dziurdz 11-02-2003 02:29 AM

Re: Get Windows Task-Names?!
 
Purl Gurl wrote:
> Kasper, your use of tasklist has rattled my memory
> of tlist which will be added to my Perl site as an
> effective method to list all running processes
> using Win32 DOS system access.


Here is the complete code I wrote:

sub IMAGENAME { 0 }
sub PID { 1 }
sub SESSIONNAME { 2 }
sub SESSION { 3 }
sub MEMUSAGE { 4 }
sub STATUS { 5 }
sub USERNAME { 6 }
sub CPUTIME { 7 }
sub WINDOWTITLE { 8 }

sub get_tasks {

my @tasks = split "\n", `tasklist.exe /v`;
my @format = split " ", $tasks[2];
@tasks = @tasks[3 .. $#tasks];

for (my $i = 0; $i <= $#tasks; ++$i) {

my $task = [];
my $line = $tasks[$i];

foreach my $f (@format) {
my $str = substr $line, 0, (length $f) + 1, '';
$str =~ s/\s*$//;
push @$task, $str;
}

$tasks[$i] = $task;

}

return wantarray ? @tasks : \@tasks;

}

foreach ( get_tasks() ) {
print $_->[WINDOWTITLE], "\n";
}

However, tasklist.exe seems to limit the window title to 72 characters.
Everything else works fine :-)

Kasper

--
HTML::KTemplate | Perl module to process HTML templates.
http://search.cpan.org/dist/HTML-KTemplate/

Kopierschutz-Nein-Danke.de | Gegen kopiergeschützte Un-CDs!
http://www.kopierschutz-nein-danke.de/


Kasper Dziurdz 11-02-2003 01:15 PM

Re: Get Windows Task-Names?!
 
Purl Gurl wrote:
> I would like to read a sample of your raw output from tasklist.
> Your code suggests WinXP tasklist returns are quite different
> than traditional tlist returns:


Tasklist.exe returns a list in the following format:

Abbildname PID Sitzungsname Sitz.-Nr.
========================= ===== ================ ==========
System Idle Process 0 Console 0
System 4 Console 0
smss.exe 348 Console 0
mozilla.exe 1992 Console 0

As you mentioned, tlist.exe does not always have the correct window
title and does not return the cpu time etc.

> Also of interest, a question which appears here infrequently
> is how to kill a process under Win32. This kill.exe listed
> at that ftp site is specifically designed for killing off
> Windows tasks via DOS, which is highly adaptable to Perl.
> Usual caution would apply of a process no longer running
> when a kill pid command is executed, or a new process
> is running under a previously used pid number.
>
> Clearly many of these programs not available on OEM disks
> will make for superior replacements for Perl modules which
> often do not perform as claimed.


Perhaps something for a new module like Win32::Tools as an interface to
these programs?!

Kasper

--
HTML::KTemplate | Perl module to process HTML templates.
http://search.cpan.org/dist/HTML-KTemplate/

Kopierschutz-Nein-Danke.de | Gegen kopiergeschützte Un-CDs!
http://www.kopierschutz-nein-danke.de/


Kasper Dziurdz 11-02-2003 03:58 PM

Re: Get Windows Task-Names?!
 
TASKLIST /V /FO CSV /NH

"System Idle Process","0","Console","0","20 K","Wird
ausgeführt","NT-AUTORITÄT\SYSTEM","1:36:28","Nicht verfügbar"
"System","4","Console","0","216 K","Wird
ausgeführt","NT-AUTORITÄT\SYSTEM","0:09:56","Nicht verfügbar"
"smss.exe","348","Console","0","344 K","Wird
ausgeführt","NT-AUTORITÄT\SYSTEM","0:00:00","Nicht verfügbar"
"mozilla.exe","236","Console","0","38.496 K","Wird
ausgeführt","KASPER-XXXXXXXX\Kasper Dziurdz","0:00:07","Google - Mozilla"

Easier to process and no limit to 72 characters!

Kasper

--
HTML::KTemplate | Perl module to process HTML templates.
http://search.cpan.org/dist/HTML-KTemplate/

Kopierschutz-Nein-Danke.de | Gegen kopiergeschützte Un-CDs!
http://www.kopierschutz-nein-danke.de/


Kasper Dziurdz 11-03-2003 12:36 AM

Re: Get Windows Task-Names?!
 
Purl Gurl wrote:
> Does XP have an equal for "kill.exe" as found in the
> resource kit for older Win systems such as 9.x and
> Win2K / NT5?


Yes, taskkill.exe:

http://www.microsoft.com/technet/pro...s/taskkill.asp

http://www.microsoft.com/technet/pro...s/tasklist.asp

Small rewrite again:


sub tasklist {

my @tasks = split "\n", `tasklist.exe /v /fo CSV /nh`;
shift @tasks if $tasks[0] eq ''; # remove empty line

foreach (@tasks) {
my $task = [];

foreach my $str (split ',') {
substr $str, 0, 1, '';
substr $str, -1, 1, '';
push @$task, $str;
}

$_ = $task;
}

return wantarray ? @tasks : \@tasks;

}


Thanks for the help!

Kasper

--
HTML::KTemplate | Perl module to process HTML templates.
http://search.cpan.org/dist/HTML-KTemplate/

Kopierschutz-Nein-Danke.de | Gegen kopiergeschützte Un-CDs!
http://www.kopierschutz-nein-danke.de/



All times are GMT. The time now is 10:11 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.