473,854 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 16171
"SeC" <se*****@gmail. comwrote in message
news:11******** **************@ 79g2000cws.goog legroups.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.goog legroups.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.goog legroups.com...
>
Willy Denoyette [MVP] napisal(a):
>"SeC" <se*****@gmail. comwrote in message
news:11******* *************** @79g2000cws.goo glegroups.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.goog legroups.com...

Willy Denoyette [MVP] napisal(a):
"SeC" <se*****@gmail. comwrote in message
news:11******** **************@ 79g2000cws.goog legroups.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******@hotma il.comwrote in message
news:11******** **************@ 79g2000cws.goog legroups.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_EVEN T 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 "TerminateProce ss" 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
'TerminateProce ss" which cannot be trapped and that was my exact point.

Willy.

Dec 7 '06 #6
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te:
>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_EVEN T 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 "TerminateProce ss" 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.c om...
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te:
>>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
messagequeu e or a CTRL_CLOSE_EVEN T 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 "TerminateProce ss" 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.bewro te:
>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_NOACTIVAT E.

>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.c om...
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te:
>>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_NOACTIVAT E.

>>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
4026
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
503
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 termination of the application during a system shutdown, logoff, end task or end process?
6
5178
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 documents (txt, MS Office files, pdf, pictures,…) from inside my app. It must start the file with the adequate external program (Notepad, MS Office programs, Acrobat Reader, some Picture viewer,... ) and be notified when this programs closes the...
5
11273
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 to avoid the overhead of writing to the console if it is not visible, eg I am running inside a WinForm application. thanks
2
1332
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 question: is there a way to detect this at design time?) Thanks, Steve
1
2737
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 etc... I stumbled across the GetWindow API but am unsure how to work it properly. The only examples I found are in VBA or VB6. Private Declare Function GetWindow _
1
4134
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 a number of promising examples but unfortunetly they are VB6 examples and just don't seem to be working correctly: ---------------Start Code------------------------------------
8
3039
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 the plant with a wireless connection. There are some pockets of non-connectivity. I've been tasked with disabling the submit button on the form if the network is unavailable. Possible solution: I can instantiate a timed process (VB.NET 2.0
4
13283
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 it: if (e.CloseReason == CloseReason.TaskManagerClosing) { MessageBox.Show("from task manager"); }
0
9901
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9750
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10672
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9510
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7909
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7077
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.