News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Task Cleaner?

Started by cman, November 05, 2010, 09:02:02 PM

Previous topic - Next topic

cman

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.....

theunknownguy

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


cman

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.

theunknownguy

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

elmo

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
be the king of accounting programmer world!

qWord

there are several methods to list current running processes. One is to use the EnumProcesses(). To see which process has been started or closed you must continual list all running processes and compare results with previous ones.
FPU in a trice: SmplMath
It's that simple!

elmo

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
be the king of accounting programmer world!

qWord

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)
FPU in a trice: SmplMath
It's that simple!

Slugsnack

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

qWord

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

qWord
FPU in a trice: SmplMath
It's that simple!

baltoro

SysInternals Process Explorer 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.
Baltoro