473,231 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Search through list of tasks in task manager

Hi,

I am a newbie at C#. Here is my current problem:

I want my application to iterate through the list of tasks presented in
task manager. I want it to look at the task names and if a certain task
exist in the task list I want to kill it (as nice as possible).

I started the task manager with the following row:
System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\taskmgr.exe");

I then get the handle to the task manager by doing (Win32 is a
DllImport of user32.dll):
int iHandle = Win32.FindWindow(null, "Windows Task Manager");

Can I use the EnumChildWindows, GetWindowText, GetClassName (all of
them from the windows 32 API) for getting the handle to the
Applications tab (and thereby get to the list of tasks)? or how do I go
about?

Feb 15 '06 #1
6 7120
It sounds to me you are going the long way to get what you want. Take a look
at the Process class in the System.Diagnostics namespace.

The class has a static method called GetProcessesByName, if it appears in
the array it returns then voila it is a running process. You can then call
the Kill method on it.

--
-Demetri
"Marcus" wrote:
Hi,

I am a newbie at C#. Here is my current problem:

I want my application to iterate through the list of tasks presented in
task manager. I want it to look at the task names and if a certain task
exist in the task list I want to kill it (as nice as possible).

I started the task manager with the following row:
System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\taskmgr.exe");

I then get the handle to the task manager by doing (Win32 is a
DllImport of user32.dll):
int iHandle = Win32.FindWindow(null, "Windows Task Manager");

Can I use the EnumChildWindows, GetWindowText, GetClassName (all of
them from the windows 32 API) for getting the handle to the
Applications tab (and thereby get to the list of tasks)? or how do I go
about?

Feb 15 '06 #2
Thanks a lot for answering, I really appriciate it.

I am probably going the long way (which I dont really want), so thanks
again for your help.

I wonder if I maybe used the wrong word when I said I wanted to kill a
task. What I really want is to kill an application (or is it the same
thing?)
As far as I know an application can consist of several processes.

What I want to do is to first retrieve all the application names and if
I find for instance the substring "Microsoft Word" as part of an
application name, I want to kill that application as gentle as
possible.

So I guess the first thing I need to do is get the running application
names (how can I do that), and then if I find an application that I
want dead, I need to find out which processes are related to that
application name and kill those (or is there methods of doing this at
application level instead of at process level)

Is there a good solution to this one?

Feb 16 '06 #3

"Marcus" <ma************@koping.net> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
| Thanks a lot for answering, I really appriciate it.
|
| I am probably going the long way (which I dont really want), so thanks
| again for your help.
|
| I wonder if I maybe used the wrong word when I said I wanted to kill a
| task. What I really want is to kill an application (or is it the same
| thing?)
| As far as I know an application can consist of several processes.
|
| What I want to do is to first retrieve all the application names and if
| I find for instance the substring "Microsoft Word" as part of an
| application name, I want to kill that application as gentle as
| possible.
|
| So I guess the first thing I need to do is get the running application
| names (how can I do that), and then if I find an application that I
| want dead, I need to find out which processes are related to that
| application name and kill those (or is there methods of doing this at
| application level instead of at process level)
|
| Is there a good solution to this one?
|

The first question that comes to mind is why do you want to kill
applications?
There is simply no way to .... kill as gentle as ..., killing a process is a
rude operation, you always throw away all work done so far, is this really
what you are looking for?

Willy.
Feb 16 '06 #4
Yes it is. I am used to the Unix world and in there you have got 2
different ways of terminating a process. Either you can make a kill or
you can make a kill -9. If you leave the -9 out of it, then you let the
OS handle the kill so that the killed process exits gracefully (files
held be the process closed in god manner), the process telling its
parent its exit status etc. If you do a kill -9 then you just brutally
kills it.
Kind of the same as when you close down Microsoft Windows (the OS
itself), you are sometimes asked to wait for some process to end
(kill), but you have the choice of terminating it right away (kill -9).
So to your question: I want to send the same message to the application
that would be sent if I did it the file->exit way. This be WM_CLOSE or
whatever is used, I dont know. I just want it automated from inside
another application's code (selection block or something alike).

Feb 16 '06 #5
I'm telling ya, everything you need is in the System.Diagnostics namespace in
the Process class.

If you want a process to exit "gracefully" then call the Close and/or
CloseMainWindow methods.

If you want to be rude about it, just call the Kill method. Here is a link,
watch for word wrap:
http://msdn.microsoft.com/library/de...ClassTopic.asp

If you want to execute the File -> Exit in a running windows application
then take a peek at the SendKeys class in the System.Windows.Forms namespace.
Here is a link, watch out for word wrap:
http://msdn.microsoft.com/library/de...classtopic.asp

--
-Demetri
"Marcus" wrote:
Yes it is. I am used to the Unix world and in there you have got 2
different ways of terminating a process. Either you can make a kill or
you can make a kill -9. If you leave the -9 out of it, then you let the
OS handle the kill so that the killed process exits gracefully (files
held be the process closed in god manner), the process telling its
parent its exit status etc. If you do a kill -9 then you just brutally
kills it.
Kind of the same as when you close down Microsoft Windows (the OS
itself), you are sometimes asked to wait for some process to end
(kill), but you have the choice of terminating it right away (kill -9).
So to your question: I want to send the same message to the application
that would be sent if I did it the file->exit way. This be WM_CLOSE or
whatever is used, I dont know. I just want it automated from inside
another application's code (selection block or something alike).

Feb 16 '06 #6
Thank you very much Demetri. I will look into this tonight!
Demetri skrev:
I'm telling ya, everything you need is in the System.Diagnostics namespace in
the Process class.

If you want a process to exit "gracefully" then call the Close and/or
CloseMainWindow methods.

If you want to be rude about it, just call the Kill method. Here is a link,
watch for word wrap:
http://msdn.microsoft.com/library/de...ClassTopic.asp

If you want to execute the File -> Exit in a running windows application
then take a peek at the SendKeys class in the System.Windows.Forms namespace.
Here is a link, watch out for word wrap:
http://msdn.microsoft.com/library/de...classtopic.asp

--
-Demetri


Feb 16 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Greg Bryant | last post by:
I'm doing some work for a company that has an auction site running in coldfusion. They're not real happy with it, and it needs a major overhaul, so I'm looking at redoing it, and while I'm at it,...
1
by: Dominic | last post by:
Just in case someone is interested. I came up with this solution since my previous posting. Maybe you've got some other ideas or critcism. I'll listen ;-) Ciao, Dominic P.S. Python is...
83
by: D. Dante Lorenso | last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org is extremely SLOW. Considering this is a website for a database and databases are supposed to be good for indexing content, I'd...
5
by: Dougal Fair | last post by:
Hello, I have written a vb.net program that invokes an Access2000 report in Preview mode, so that it shows on the screen. My program then goes on its merry way and the user can read the report...
4
by: PJSimon | last post by:
I have added task list items to my VB.Net project. After checking the project into source safe, another user gets the latest version. When the other user opens the project, the task list is empty....
0
by: Chris Dunaway | last post by:
I use 'TODO's to add items to the task list to remind me of things that I need to do. I right click the task list and choose Show Tasks > All so that all items are shown. This works fine. ...
0
by: pdm | last post by:
In one lookup table I have 4 tasks listed. Every task can occur or not during a day in one, more or all timeshifts. I have 3 timeshifts : morning - afternoon - evening. morning | afternoon |...
0
oll3i
by: oll3i | last post by:
import javax.swing.*; import java.awt.event.*; import java.util.ArrayList; import java.util.List; import java.util.concurrent.*; import java.lang.reflect.*; public class Exec1 extends JFrame...
8
by: Gabriel | last post by:
Hi all Just wondering if someone could clarify this behaviour for me, please? , , , , , ] , , , , , ] Well what I was expecting to end up with was something like: >>tasks , , , , , ]
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.