1

I am having one windows forms application which is designed to do specific tasks in background. Now I want to make sure that this application should be running all the time. No one should able to close it. If some one closed it from Task Manager (Kill it) then it should restart it self.

I had couple of options for that. I have tried to make one window service which has timer and which can be check at every 1 minute that if process is not found then it will launch the process. But I have gone through couple of articles and they are saying that this is not nice idea. Is there any other way round to keeping alive my application in windows.

In my idea also if someone closes my service then also I can't detect if my WinForms application is closed or running. What is best way to do so? I am ready to give highest privileges and I have thought that option as well that If someone kill process of my application then computer should be shut down it self.

Please share better idea to do so.

Mehrad
  • 4,093
  • 4
  • 43
  • 61
Jaynesh Shah
  • 158
  • 1
  • 1
  • 14
  • 3
    Is this going to be a virus? :P – Mehrad Jun 25 '14 at 05:37
  • It's not a good idea to force users to have your application open all the time! IMHO ask them nicely if the application is closing if you really should and if they say yes go away! If there is something that you need to do in the background all the time but it into a Service (and yes a user/admin will be able to close this too - and YES they SHOULD be able to!) – Random Dev Jun 25 '14 at 05:41
  • If this is a machine over which you should have this much control, you should be able to trivially remove other user's ability to launch task manager and kill processes. – Damien_The_Unbeliever Jun 25 '14 at 06:52
  • Hi I too have same requirement. If you solved it using windows service plz reply on my question. http://stackoverflow.com/questions/33385338/run-windows-application-from-windows-service/33386814#33386814 – Hussain Oct 29 '15 at 05:26
  • @Hussain Only option I got is name your window service "WinHost32" or "System64Host" so user would be afraid to close it. and if user tries to close it that do you really want to close it closing this application will require computer restart and you can also do that when user close the service restart the computer so on next startup service will automatically started. – Jaynesh Shah Nov 06 '15 at 23:36

2 Answers2

0

you should know that it is impossible to prevent task manager not to close your application. and its not a proper idea to force the user.

But, if you insist I think the best way is through services with timer or thread whichever suits your solution to check its process and run it if not exists. and you didn't mention in your post that what was the reason of not using this method and why it is not a good method.

hope it helps you decide better.

H.A
  • 66
  • 1
  • 11
0

If you don't want the user closing your app, make it as difficult for him as possible:

  • launch it maximized
  • remove the frame of the window (and close, maximize,minimize buttons with it)
  • launch it TopMost
  • set ShowInTaskbar of your forms to false
  • ask 10 times "are you sure you want to exit???" :)
  • set e.Cancel to true in FormClosing event, etc...

About the Task Manager:

Then, if the user still manages to close your app, you can do what most people on the Internet consider a Very Bad Idea and start it from the service. As long as you are concious of the risks.

There are plenty of resource out there that tell you how to start an interactive app from the service (so evidently some people are doing it too), for example:

http://blogs.msdn.com/b/winsdk/archive/2009/07/14/launching-an-interactive-process-from-windows-service-in-windows-vista-and-later.aspx

Community
  • 1
  • 1
Arie
  • 5,251
  • 2
  • 33
  • 54