Click here to Skip to main content
15,886,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried the Application.ApplicationExit event handler. When i end task the process it just closes the application and the event handler is not triggered at all. I want to catch this time since its important for break management. The purpose is to track exact time of closing the application.
Posted
Comments
SoMad 26-May-14 6:18am    
Your are asking if it is possible to prevent a program from being killed through Task Manager, but that is not really your core problem, right? You just want a way to have a time stamp of when the program was closed.

I think you should change your mindset and ask for ways to capture when a program is no longer running. I can think of several ways of doing that, but I don't know if you also have to account for the case where the user pulls the plug on the system.

Soren Madsen
Hassan(Aych Jay) 26-May-14 6:28am    
Please share your views. I have to account for events when the application is closed or forced to stop working. if PC power plug is pulled that's OK with the administration.
SoMad 27-May-14 16:22pm    
Sorry, I did not get a notification about your comment because you did not reply directly to my comment (it's an easy mistake to make and we see it all the time).

Anyway, I see that you resolved this by taking the Administrator privileges away from the users.

If I was correct when I said above, that you just want a way of determining when the application is closed (which is the last sentence in your question) and you don't really need to restart it, then one (simple/naïve) method could be to have the application periodically write a time stamp to a file and whenever you need to determine when it was closed, you get the time stamp from that file.
It is an oversimplification of a basic method of handling the problem. You could also have a service monitoring in the background (just as you mentioned you tried), but instead of restarting the application, the service stores the time stamp somewhere and basically operates in a more stealthy way than actively restarting the application.

Soren Madsen

It may surprise you but client's computer belongs to the client! So on what base do you want to prevent him to kill your app?!
To our business - there is no event that guaranteed to be called if the process killed rudely - the reason is that the event chain is inner to your process, but the kill request comes from the outside and will not wait for your process until response but will kill it within predefined time-frame...
 
Share this answer
 
Comments
Hassan(Aych Jay) 26-May-14 3:21am    
I agree with you that the clients computer belongs to the client. The employees computer belongs to the employer. The employee has no right to close an application which is designed to monitor employee breaks. Yes the event chain is inner to your process, but the kill request comes from the outside and will not wait for your process until response but will kill it within predefined time-frame. Is there any way I can keep a track.
Kornfeld Eliyahu Peter 26-May-14 5:43am    
No. There is no reliable way to track kill of process...
You may think of service that can be checked and restarted from some central machine (server) of your corporate network...
make a service check if application is running if its not running start the application in the service
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 26-May-14 5:43am    
Service can be killed too...
Hassan(Aych Jay) 26-May-14 5:44am    
IF i make a service to start the application then they can close that service as well.
SoMad 26-May-14 5:50am    
Are you saying these users have Admin privileges on the systems? In that case it will be tricky to find a solid way of achieving your goal.

Soren Madsen
Kornfeld Eliyahu Peter 26-May-14 6:01am    
I saw a lot of corporate networks where the main user is local administrator - the main reason is help sys-admin to do installations with ease...
SoMad 26-May-14 6:03am    
Sure, I have that at work too. That is why I am asking him if these particular users have those privileges.

Soren Madsen
its not possible and dont try this also
bcose its not a logical thing
 
Share this answer
 
Comments
phil.o 26-May-14 7:50am    
Please avoid textspeak on this forum.
Sanjay K. Gupta 26-May-14 8:50am    
Please do not use sms/chat language.
I tried to solve it via Application.ApplicationExit. Then i tried by using a windows service but that service was also closed. So as a last resort i have taken administrator privileges from those users and installed a software that stops them from opening task manager and control panel. Now the application seems to run smoothly monitoring breaks.
 
Share this answer
 
Comments
SoMad 27-May-14 18:23pm    
Just a thought, but if you want to do part of your handling in a service and you are afraid the users might stop it, you can add logic to prevent the user from stopping the service.

Even though I have Local Administrator privileges on my system at work, there are services I cannot stop. I admit I have not tried to see if I can kill them through Task Manager, but I suspect not.

You are implementing the service, so you could simply choose to only handle the Stop request if the user is logged in as Administrator or whatever criteria you can come up with.

Soren Madsen

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900