The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: cman on November 05, 2010, 09:02:02 PM

Title: Task Cleaner?
Post by: cman on November 05, 2010, 09:02:02 PM
Is it possible to write an application that loops through currently running applications and kills applications that are of the status "not responding"? Has anyone written anything like this ? Thanks for any information.....
Title: Re: Task Cleaner?
Post by: theunknownguy on November 05, 2010, 09:15:39 PM
Quote from: cman on November 05, 2010, 09:02:02 PM
Is it possible to write an application that loops through currently running applications and kills applications that are of the status "not responding"? Has anyone written anything like this ? Thanks for any information.....

You might be looking for:

IsHungAppWindow

http://msdn.microsoft.com/en-us/library/ms633526%28VS.85%29.aspx

Just open each process, check if its hung and kill it

Title: Re: Task Cleaner?
Post by: cman on November 05, 2010, 09:42:48 PM
Thanks for the information! :U I kind of need a basic outline on the algorithm ( like use so and so API to search through a process data structure or whatever , which API to kill the offending processes , etc. ) but thanks for getting me started.
Title: Re: Task Cleaner?
Post by: theunknownguy on November 05, 2010, 09:52:01 PM
Quote from: cman on November 05, 2010, 09:42:48 PM
Thanks for the information! :U I kind of need a basic outline on the algorithm ( like use so and so API to search through a process data structure or whatever , which API to kill the offending processes , etc. ) but thanks for getting me started.

Since the Hung API uses Hwnd use EnumWindows:

http://msdn.microsoft.com/en-us/library/ms633497%28VS.85%29.aspx

Use GetWindowThreadProcessID to get the PID of the process with only the Hwnd:

http://msdn.microsoft.com/en-us/library/ms633522%28VS.85%29.aspx

Later use OpenProcess for open the process (so redundant) with PROCESS_ALL_ACCESS:

Finally use GetExitCodeProcess and TerminateProcess

PS: You can do thons of other ways  :U
Title: Re: Task Cleaner?
Post by: elmo on April 13, 2011, 05:57:39 AM
I press ctrl+alt+del, then I click tab Applications
it will list all active application who it's caption avail in taskbar

If I close one active application in the taskbar, it will refresh and show remain
active application who it's caption still avail in taskbar

How to detect in our program if we close/open application?
I mean what message (WM_xxxxx) ?

Pardon me for my bad english
thank you
Title: Re: Task Cleaner?
Post by: qWord on April 13, 2011, 06:16:58 AM
there are several methods to list current running processes. One is to use the EnumProcesses() (http://msdn.microsoft.com/en-us/library/ms682629(v=vs.85).aspx). To see which process has been started or closed you must continual list all running processes and compare results with previous ones.
Title: Re: Task Cleaner?
Post by: elmo on April 13, 2011, 06:29:39 AM
no, qword.
what I mean is:

I make an app. Then, I run it.

At the other hand, I use WinXP to close/open an application

if I close an app with WinXP, I want to show in my app "WinXP close an app"
if I open an app with WinXP, I want to show in my app "WinXP open an app"

so, my app must detect a message. But, what message (WM_xxxxx) that detact this action?
thank you
Title: Re: Task Cleaner?
Post by: qWord on April 13, 2011, 06:48:29 AM
elmo,
there is no such message.
To see which application (process) was started/close you must keep track of running processes by listing them continually (e.g. each 0.5-1 second)
Title: Re: Task Cleaner?
Post by: Slugsnack on April 13, 2011, 07:12:18 AM
Quote from: theunknownguy on November 05, 2010, 09:52:01 PM
Quote from: cman on November 05, 2010, 09:42:48 PM
Thanks for the information! :U I kind of need a basic outline on the algorithm ( like use so and so API to search through a process data structure or whatever , which API to kill the offending processes , etc. ) but thanks for getting me started.

Since the Hung API uses Hwnd use EnumWindows:

http://msdn.microsoft.com/en-us/library/ms633497%28VS.85%29.aspx

Use GetWindowThreadProcessID to get the PID of the process with only the Hwnd:

http://msdn.microsoft.com/en-us/library/ms633522%28VS.85%29.aspx

Later use OpenProcess for open the process (so redundant) with PROCESS_ALL_ACCESS:

Finally use GetExitCodeProcess and TerminateProcess

PS: You can do thons of other ways  :U
PROCESS_ALL_ACCESS should not be used, see here:
http://msdn.microsoft.com/en-us/library/ms684880(v=vs.85).aspx
Title: Re: Task Cleaner?
Post by: qWord on April 13, 2011, 03:52:27 PM
hi elmo,

I just like the idea of receiving messages when process are created or closed,so I've written an little library doing this:

lib: process watcher (http://www.masm32.com/board/index.php?topic=16434.new#new)

qWord
Title: Re: Task Cleaner?
Post by: baltoro on April 13, 2011, 04:07:01 PM
SysInternals Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653) is also good for killing rogue apps,...but, will not do so automatically.
It has the advantage, as Slugsnack has pointed out above, of handling security for you.