Solved

End process message

Posted on 2002-07-01
14
299 Views
Last Modified: 2010-04-04
hi
Is there any way to know when killing process by 'End Process' from   Windows Task Manager?
0
Comment
Question by:udic
  • 4
  • 4
  • 2
  • +2
14 Comments
 
LVL 3

Expert Comment

by:raidos
ID: 7124161
As far as i know the "End process" from the Task manager sends a message to the applications mainform...WM_COMMAND/WM_SYSCOMMAND with wparam or lparam containing SC_CLOSE i forget which, or a simple WM_CLOSE....and if the application is inresponsive then the task manager pulls up a dialog and you are asked to terminate the application or wait or cancel...the terminate request is not trapable from your application but the messages are..

Regards
//raidos
0
 

Author Comment

by:udic
ID: 7124197
hi
i added dialog message when those messages arrive but nothing happen.

udi
0
 
LVL 3

Expert Comment

by:raidos
ID: 7124260
My mistake...it doesn't send any messages when you use the "End process" button, it just Calls TerminateProcess(Your_apps_ProcessHandle, ExitCode);

and that is as far as i know not hookable or detectable...

perhaps if you could "hack" the Kernel32.Dll or something similar and have it run your own TerminateProcess...
but that's more work than it's worth IMHO...

would probably be easier t write a little agent that polls the application to see if it still there...if not then asume it's been killed...and take the apropriate action..

hope this helps..
//raidos
0
 
LVL 2

Expert Comment

by:Griffon
ID: 7124294
you could just hide the application you are writing (if that is the case) from the menu in the task manager this is done by blanking the application name in the project code..

  Application.Title := '';

this will enable you to ensure that the user terminates via the program and not from the task bar.

here are some usefull ideas for playing with the system tray and the taskbar.

http://delphi.about.com/library/weekly/aa022701a.htm?terms=task+manager

0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7130574
To hide your process from the running tasks list, you can use RegisterServiceProcess in kernel32.dll:

Put this in 'implementation':

function RegisterServiceProcess(dwProcessID, dwType: DWORD): DWORD;stdcall; external 'KERNEL32.DLL';

To hide it, use 0 for dwType (1 to show it)

dwProcessID can be obtained by calling "GetCurrentProcessID".

Hope it helps
0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7130576
Woops:) mixed 'em up.

dwType: 1 to hide and 0 to show
0
 
LVL 20

Expert Comment

by:Madshi
ID: 7134013
Are we talking about win9x or winNT family?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:udic
ID: 7134804
i'm working on win2k
many thanks, to all of you.
but i dont want to hide the process.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 7134838
To be notified about "end task" in 2k you would probably have to hook into the task manager dialog. You could either try to hook/subclass the "end task" button or you could try to hook the TerminateProcess API. For both purposes you would have to put your hooking stuff into a little dll and inject it into the task manager process. You could use SetWindowsHookEx to do that, also to detect when the task manager window is created.

If you are a top hacking expert you now should know what you have to do. If you're not, better forget about this question, because this is quite a difficult thing to do for a non hacking expert, sorry...

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 7134839
But perhaps if you tell us for what purpose you need the notification, we might find an easier compromise solution for your problem...
0
 

Author Comment

by:udic
ID: 7137012
Thanks alot,
i build a service shell that launch, close and detect when the application was closed (by process list).
when the user logoff the application was close (and stop the service).

Thanks again
udi
0
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 7137072
Create an extra thread in your service. In this thread call "WaitForSingleObject(applicationProcessHandle, INFINITE)". When that call returns, the application was stopped. You can't detect, though, how it was stopped. If the application is your own, it should notify your service before it is stopped friendly by the user. This way you should all the info you need.

Regards, Madshi.
0
 
LVL 2

Expert Comment

by:Griffon
ID: 7137126
Just wrote a program that does that and because the task manager seems to shut it down without sending out a call I hid the program from task manager to prevent the user closing the program.

The program grabbed the correct shut down using a system hook. The only problem with this is the fact that if the machine crashes then it will not log off the easiest way to overcome that is to make it so that if a user logs back into thier area within a certain amount of time it will not make another login record but continue to use the existing one.

Ok it is not exactly what you want to do but that is how I sorted it out to work. I will be interested in finding out the way you overcome the problem if indeed you do.

Griffon
0
 

Author Comment

by:udic
ID: 7137818
Thanks alot
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now