473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Detect 'End Process' in application

SeC
Hi.
Is there any way to detect if application is being killed by 'End
Process' via Task Manager ?

Dec 7 '06 #1
9 16001
"SeC" <se*****@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
Hi.
Is there any way to detect if application is being killed by 'End
Process' via Task Manager ?
No there isn't, and that's why you should never kill an application unless the application
is blocked and none of it's threads can ever make any progress.

Willy.

Dec 7 '06 #2
SeC

Willy Denoyette [MVP] napisal(a):
"SeC" <se*****@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
Hi.
Is there any way to detect if application is being killed by 'End
Process' via Task Manager ?

No there isn't, and that's why you should never kill an application unless the application
is blocked and none of it's threads can ever make any progress.

Willy.
Yeah, I know that, but person who uses my application don't. He can
terminate process just 'because' and I need to perform some actions
when this happen. So there is nothing I can do about it ?

Dec 7 '06 #3
"SeC" <se*****@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
>
Willy Denoyette [MVP] napisal(a):
>"SeC" <se*****@gmail.comwrote in message
news:11**********************@79g2000cws.googlegr oups.com...
Hi.
Is there any way to detect if application is being killed by 'End
Process' via Task Manager ?

No there isn't, and that's why you should never kill an application unless the
application
is blocked and none of it's threads can ever make any progress.

Willy.

Yeah, I know that, but person who uses my application don't. He can
terminate process just 'because' and I need to perform some actions
when this happen. So there is nothing I can do about it ?

As I said, No there isn't. Educate your users not to kill processes or remove "Task manager"
from the task bar by applying group policies.

Willy.

Dec 7 '06 #4
I may be putting my foot in my mouth here, and I don't have a
solution, but I think you can do this some how. I'm sure it would take
some advanced coding, but I think it can be done. I have dealt with
viruses that when you kill the process it starts right back up. I've
also had processes that have ran in such a way that Task Manager cannot
kill them at all. If the application is truely not 'locked up' and is
running, is there no que or system call that could be monitored to see
it this process in in the que or having a system call issues to kill
it, and then respond by doing some cleanup - maybe cancelling itself
from the que/system call, doing cleanup, and closing properly? If the
application is truely 'locked' then it wouldn't matter anyway.
I am not good at the current programming languages and such, but I
find things like this to fit into that 'never say never' category.
There is usually a way to do almost anything in code.
Also, you're assuming that this programmer is in a position to
enforce group policy. I write retail applications and have no power
over what is enforced though group policy, assuming they are even
running in a server based network. Messing with local policies when you
install software on someone elses machine is not good practice. And
considering you are an MVP, you have been 'computering' for a bit and
you know users will not listen to you many times and will do what they
want, when they want, and then tell you they didn't do it!
Look into this more, I'll bet you 99.99% chance this can be done
some way.
Willy Denoyette [MVP] wrote:
"SeC" <se*****@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...

Willy Denoyette [MVP] napisal(a):
"SeC" <se*****@gmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
Hi.
Is there any way to detect if application is being killed by 'End
Process' via Task Manager ?


No there isn't, and that's why you should never kill an application unless the
application
is blocked and none of it's threads can ever make any progress.

Willy.
Yeah, I know that, but person who uses my application don't. He can
terminate process just 'because' and I need to perform some actions
when this happen. So there is nothing I can do about it ?


As I said, No there isn't. Educate your users not to kill processes or remove "Task manager"
from the task bar by applying group policies.

Willy.
Dec 7 '06 #5
"Andrew Meador - ASCPA, MCSE, MCP+I, Network+, A+" <am******@hotmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
I may be putting my foot in my mouth here, and I don't have a
solution, but I think you can do this some how. I'm sure it would take
some advanced coding, but I think it can be done. I have dealt with
viruses that when you kill the process it starts right back up. I've
also had processes that have ran in such a way that Task Manager cannot
kill them at all. If the application is truely not 'locked up' and is
running, is there no que or system call that could be monitored to see
it this process in in the que or having a system call issues to kill
it, and then respond by doing some cleanup - maybe cancelling itself
from the que/system call, doing cleanup, and closing properly? If the
application is truely 'locked' then it wouldn't matter anyway.
I am not good at the current programming languages and such, but I
find things like this to fit into that 'never say never' category.
There is usually a way to do almost anything in code.
Also, you're assuming that this programmer is in a position to
enforce group policy. I write retail applications and have no power
over what is enforced though group policy, assuming they are even
running in a server based network. Messing with local policies when you
install software on someone elses machine is not good practice. And
considering you are an MVP, you have been 'computering' for a bit and
you know users will not listen to you many times and will do what they
want, when they want, and then tell you they didn't do it!
Look into this more, I'll bet you 99.99% chance this can be done
some way.

Well, let me be more specific, I'm talking about the "kill" in OP's question while he's
asking about the "End process". So my previous answer "No it can't be done" might be wrong,
all depends on why the user decides to use 'Taskman' to terminate an application, let me
explain.
Using "End task" in taskman will try to "End a process" or try to "Kill " a process,
taskman's "End process" will ask the OS to send a WM_CLOSE message to the UI thread
messagequeue or a CTRL_CLOSE_EVENT to a console program. Both of these can be handled by the
offending application. If the application does not respond to the message or the event in a
timely fashion, the OS will "kill" the process by calling Win32's "TerminateProcess" API.
The latter cannot be trapped, simply because no more user code will run in that process, the
user portion of a process is cleaned up without returning a thread quantum to the process,.
Note that here I'm saying user portion, a process that get's stucked into kernel space (say
in a driver) won't go away completely (only the user's portion will) if the (badly behaving)
driver doesn't clean-up and return to the OS, this is what you may have noticed using
taskman.
Now the whole question is - why does the end-user use taskman to *end* a task? Isn't it
easier to close/exit the application in a normal way? My guess is that the application is
stucked somewhere (endless loop, dead-locked, locked in kernel, etc..) and the user has no
other means than using "taskman" to terminate the application, but *if* the application is
stucked somewhere it cannot handle the message/event and it will get "killed" by
'TerminateProcess" which cannot be trapped and that was my exact point.

Willy.

Dec 7 '06 #6
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote:
>Using "End task" in taskman will try to "End a process" or try to "Kill " a process,
taskman's "End process" will ask the OS to send a WM_CLOSE message to the UI thread
messagequeue or a CTRL_CLOSE_EVENT to a console program. Both of these can be handled by the
offending application. If the application does not respond to the message or the event in a
timely fashion, the OS will "kill" the process by calling Win32's "TerminateProcess" API.

Now the whole question is - why does the end-user use taskman to *end* a task? Isn't it
easier to close/exit the application in a normal way?
I use the taskman "end task" as the standard way to exit several of my
utilities -- the small ones that run in the background and have no
user-interface as all. E.g. my "keymouse" program which turns the
right-alt-key into a virtual right-mouse-button (for people whose mice
have only one button...)
http://www.wischik.com/lu/Programmer/Keymouse

And exactly as you say, all I do is handle the WM_CLOSE message to do
the tidying up.

As for educating the user not to use EndProcess? My instinct is to
write a registry key when the application starts, and clear it when
the application ends. Upon application startup I check the key. If it
has been set then I pop up a box saying "Sorry, this application seems
to have crashed last time it was run. Where possible, try to exit the
application through File>Exit."

--
Lucian
Dec 7 '06 #7
"Lucian Wischik" <lu***@wischik.comwrote in message
news:al********************************@4ax.com...
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote:
>>Using "End task" in taskman will try to "End a process" or try to "Kill " a process,
taskman's "End process" will ask the OS to send a WM_CLOSE message to the UI thread
messagequeue or a CTRL_CLOSE_EVENT to a console program. Both of these can be handled by
the
offending application. If the application does not respond to the message or the event in
a
timely fashion, the OS will "kill" the process by calling Win32's "TerminateProcess" API.

Now the whole question is - why does the end-user use taskman to *end* a task? Isn't it
easier to close/exit the application in a normal way?

I use the taskman "end task" as the standard way to exit several of my
utilities --
Why not use the "regular" way to end a task, that is click close or Exit, is beyond me. My
guess is that you talk as a developer, you know exactly how your utilities behaves when they
get terminated from an 'external' program, a regular user should never use taskman to end a
task, he simply doesn't (and shouldn't) know what's happening when he 'kills' a task from
Taskman. I know <start rantpeople don't care that much about this all and keep running as
"administrator", kill other processes, inspect memory consumption using taskman without
knowing what memory really is, blame Windows, MSFT etc..when things go wrong when they
(Inadvertly ?) killed Winlogon or CSRSS.EXE etc., it's great to see Vista trying to get an
end to this, but as the saying goes "bad habbits never die", that's why we see a lot of
interest in turning off UAC<end rant>.
the small ones that run in the background and have no
user-interface as all. E.g. my "keymouse" program which turns the
right-alt-key into a virtual right-mouse-button (for people whose mice
have only one button...)
http://www.wischik.com/lu/Programmer/Keymouse

And exactly as you say, all I do is handle the WM_CLOSE message to do
the tidying up.
Here you mean your UI type utilities, right?, WM_CLOSE is only posted to UI threads.
>

As for educating the user not to use EndProcess? My instinct is to
write a registry key when the application starts, and clear it when
the application ends. Upon application startup I check the key. If it
has been set then I pop up a box saying "Sorry, this application seems
to have crashed last time it was run. Where possible, try to exit the
application through File>Exit."
Why not handle the WM_CLOSE and tell the user he should terminate the application through
File>Exit?
Willy.

Dec 7 '06 #8
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote:
>Why not use the "regular" way to end a task, that is click close or Exit, is beyond me.
As I said, for minimal background utilities that are too small for a
UI to be worth it (e.g. a system tray icon). So there is no place to
click Close or Exit. The task manager "Task List" is the neatest place
to list the running utility and be able to close it.

>And exactly as you say, all I do is handle the WM_CLOSE message to do
the tidying up.
Here you mean your UI type utilities, right?, WM_CLOSE is only posted to UI threads.
Come on, this is Windows. Even utilities without a UI still often need
a UI thread. (e.g. in the example I posted, it's disallowed to install
a keyboard hook unless you have a UI thread.)

Also, if you want the application to appear in the task list so that
users can close it, then it needs a UI thread and a window, even
though that window is invisible and WS_EX_NOACTIVATE.

>As for educating the user not to use EndProcess? My instinct is to
write a registry key when the application starts, and clear it when
the application ends. Upon application startup I check the key. If it
has been set then I pop up a box saying "Sorry, this application seems
to have crashed last time it was run. Where possible, try to exit the
application through File>Exit."
Why not handle the WM_CLOSE and tell the user he should terminate the application through
File>Exit?
The exercise is to educate the user not to use "End Process".

When the user terminates the program through "End Task" (->WM_CLOSE)
or clicking on the close box (->WM_CLOSE) or File>Exit, the original
poster is able to trap this and do the cleanups he needs.

He was concerned about users who use "End Process" where he can't trap
it and clean up.

Anything that produces WM_CLOSE is fine, from his perspective, so
there's no need to educate the user against it.

--
Lucian
Dec 7 '06 #9
"Lucian Wischik" <lu***@wischik.comwrote in message
news:n0********************************@4ax.com...
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote:
>>Why not use the "regular" way to end a task, that is click close or Exit, is beyond me.

As I said, for minimal background utilities that are too small for a
UI to be worth it (e.g. a system tray icon). So there is no place to
click Close or Exit. The task manager "Task List" is the neatest place
to list the running utility and be able to close it.
>>And exactly as you say, all I do is handle the WM_CLOSE message to do
the tidying up.
Here you mean your UI type utilities, right?, WM_CLOSE is only posted to UI threads.

Come on, this is Windows. Even utilities without a UI still often need
a UI thread. (e.g. in the example I posted, it's disallowed to install
a keyboard hook unless you have a UI thread.)
A process that has a UI thread (that is, has a Window registered, a message queue and a
message pump) is what I call a UI style application (or utility as you named it) , it
doesn't matter whether the window is invisible or not.
Also, if you want the application to appear in the task list so that
users can close it, then it needs a UI thread and a window, even
though that window is invisible and WS_EX_NOACTIVATE.

>>As for educating the user not to use EndProcess? My instinct is to
write a registry key when the application starts, and clear it when
the application ends. Upon application startup I check the key. If it
has been set then I pop up a box saying "Sorry, this application seems
to have crashed last time it was run. Where possible, try to exit the
application through File>Exit."
Why not handle the WM_CLOSE and tell the user he should terminate the application through
File>Exit?

The exercise is to educate the user not to use "End Process".

When the user terminates the program through "End Task" (->WM_CLOSE)
or clicking on the close box (->WM_CLOSE) or File>Exit, the original
poster is able to trap this and do the cleanups he needs.

He was concerned about users who use "End Process" where he can't trap
it and clean up.

Anything that produces WM_CLOSE is fine, from his perspective, so
there's no need to educate the user against it.
So, you are telling your users that it's OK to use "End task" but NOT "End process" from
Taskman and all of them do follow this advise? Well, that' s great for you, but our policy
is somewhat different, all users that logon into their domain account to run business
critical applications cannot use taskman (through GPM), this is something we learned the
hard way since Windows NT4 was introduced in the company a decade ago, this is not about
trusting your users (you can't trust all of them), this is about safety. And, No, we don't
install utilities that need to be started/terminated by the user that don't have a minimal
UI with 'close' or 'exit'.

Willy.

Dec 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Stephane Belzile | last post by:
Is there a way I can detect in vb.Net the power has switched to a UPS unit in case of power failure? Thanks
0
by: Will Haney | last post by:
I have a .NET application that needs to perform some last moment duties upon termination. The application has no forms with one Module containing the Sub Main. How can I detect/trap the...
6
by: Ana | last post by:
Hi! I have problems with the following scenario: My application is developed using C# under .NET. It must run on all Windows versions starting from Windows 98. The user must open different...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
2
by: Stephen Walch | last post by:
I have a managed library that needs to behave differently when used in an ASP.NET web page as apposed to a WinForms app. What is the most efficient way to detect this at run time? (Bonus...
1
by: Jeremy | last post by:
Hello, I'm thinking this may be an easy one but I am getting frustrated. How can I detect if a process is showing a modal dialog. Like "Are you sure you want to exit?", or an error message...
1
by: Jeremy | last post by:
I apologize for the repost but I am frustrated and desperate for a solution. I need to detect if an external application is displaying a modal form. I.E. dialog box or error message. I found...
8
by: BJ | last post by:
Problem: How can I code up a client side process to detect if the network is available? Synopsis: I am writing ASP.NET input forms for a Panasonic Tuff book. The users will be walking around...
4
by: e-Ricc | last post by:
Hi guys! Im trying to detect when a user "kills" my c# app using windows task manager, i've tried with the form events _closing and _closed managing for example putting an if inside to detect...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.