?
Solved

End process message

Posted on 2002-07-01
14
Medium Priority
?
317 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 

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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 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