Hi,
I wonder if there is a way to detect a deletion of an app when it's running? Lets say I have an app which is running in background and I want to delete it. Is there a way to detect this deletion by this app?
Best Regards.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 19, 2012, 9:01 AM EST
However, you can detect when an application ends by handling the Process.Exited event:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exited.aspx
It would then be possible to programatically delete the application's file by using the System.IO.File.Delete method.
In case you don't know already, you can also terminate a running app programatically using the Process.CloseMainWindow method, if it's a GUI app, or the Process.Kill method otherwise:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.closemainwindow.aspx
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx
RaysefoRank #4,173 · 360 reputationPosted Feb 19, 2012, 8:38 PM EST
Thanks for your quick reply. Let me change the question. Is there a way to avoid end a running process??? I mean If user tries to kill process from task manager or etc.
Best Regards.
VulpesRank #55 · 29.2K reputationPosted Feb 20, 2012, 3:50 AM EST
If you're writing a 'kiosk' app which you don't want the user to close, then I'd just trap the closure by handling the Process.Exited event and then restart it again with Process.Start.
Sam HobbsRank #107 · 20.5K reputationPosted Feb 20, 2012, 6:05 PM EST
There are things that can be done without programming, such as disabling a user from having permission to use the Task Manger. Note that preventing use of the Task Manager might seem to be a good solution but it is not if the user finds a similar utility to do what they want to do and there are plenty of them.
It really depends on why you need to do this. If you are doing this because an employer needs to ensure that the employee is doing something then there might be non-programming solutions. If you are doing it because the user does not like your software and they want to get rid of it from their system then the solution might be to make the program more "user-friendly". So the solution depends on many things.