?
Solved

End process message

Posted on 2002-07-01
14
Medium Priority
?
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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