Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Get Windows Task-Names?!

Reply
Thread Tools

Get Windows Task-Names?!

 
 
Kasper Dziurdz
Guest
Posts: n/a
 
      10-31-2003
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/

 
Reply With Quote
 
 
 
 
James Willmore
Guest
Posts: n/a
 
      10-31-2003
On Fri, 31 Oct 2003 13:22:07 +0100
Kasper Dziurdz <(E-Mail Removed)> 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:rocess::Info and Win32API:rocessStatus _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
 
Reply With Quote
 
 
 
 
Kasper Dziurdz
Guest
Posts: n/a
 
      11-01-2003
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/

 
Reply With Quote
 
Kasper Dziurdz
Guest
Posts: n/a
 
      11-01-2003
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/

 
Reply With Quote
 
Kasper Dziurdz
Guest
Posts: n/a
 
      11-02-2003
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/

 
Reply With Quote
 
Kasper Dziurdz
Guest
Posts: n/a
 
      11-02-2003
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/

 
Reply With Quote
 
Kasper Dziurdz
Guest
Posts: n/a
 
      11-02-2003
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/

 
Reply With Quote
 
Kasper Dziurdz
Guest
Posts: n/a
 
      11-03-2003
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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP reformated and still get c:\windows\system32\systemCORRUPT/MISING, need help please! m3ow85@gmail.com Computer Support 9 12-18-2008 10:19 PM
!Windows Live Mail replace Outlook Express on Windows XP and Windows Mail on Vista... Max Burke NZ Computing 8 05-18-2007 12:10 AM
Windows XP keeps restarting automatically before system finishes booting. GET ERROR: "We apologize for the inconveience but windows was not shutdown properly...." DaWurm Computer Support 3 11-15-2003 11:29 PM



Advertisments