473,396 Members | 1,765 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,396 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 7128
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.