0

I'm making a Parental Control program in C#. What I want to do is make my program cannot be exited. How can I do this in C#? I've searched on Google, but found nothing.

Danny
  • 1
  • 2
    you can make a windows service. which checks if program is exited by user or task manager it will restart your program – Azar Shaikh May 18 '17 at 12:41
  • This may have already been answered here [http://stackoverflow.com/questions/12422619/can-i-disable-the-close-button-of-a-form-using-c](http://stackoverflow.com/questions/12422619/can-i-disable-the-close-button-of-a-form-using-c) – J. Michael Wuerth May 18 '17 at 12:48
  • Sorry, I accidentally entered a comment twice. – J. Michael Wuerth May 18 '17 at 12:50

3 Answers3

2

You can't. The Operating System always has control, so through the OS you can always exit (force kill) an application, for example through the task manager.

A light-weight solution could be another application that checks if the app is active or not. If not, start it again. The main program checks if the check program is there and starts it if necessary.

Another solution would be to run a service under an administrative account. That would only be a feasible option if you don't need to have access to the screen of the user.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • The another app solution is great one, I'll check it – Danny May 18 '17 at 12:46
  • I have some feeling that it's not quite true (though no certainty). If we are talking about parental control - children should have restricted account on machine, without admin permissions. In such case - they should not be able to kill processes owned by "system" account, for example. – Evk May 18 '17 at 12:51
  • Who says the program is owned by an administrator? And even then, you can't show anything on the user desktop, which is the key of an application. @evk – Patrick Hofman May 18 '17 at 12:57
  • Added the service option @Evk. Hope that is a decent solution. – Patrick Hofman May 18 '17 at 13:27
  • And what will prevent user from killing that second application which is tracking the first one? Didn't downvote by the way. – Evk May 18 '17 at 13:48
  • It is quite hard to kill two programs at once. There is always a short time in between which gives the other end the opportunity to start again @Evk. Indeed, not fail save. A service that starts the app could do. – Patrick Hofman May 18 '17 at 13:49
1

Do you really mean impossible to exit ? Or just like hide the close cross or something ?

If you mean make the program impossible to kill, even in task manager, this seems to be a bad idea. If it's impossible for a user to kill a progra, how Windows would kill it ?

If I were you I would maybe protect the program shut down with a password.

Quentin S.
  • 328
  • 2
  • 16
  • Impossible to exit, yeah. The solution of Patrick seems to be nice and I'll check it – Danny May 18 '17 at 12:56
  • Maybe, but it doesn't really answer your request, since restarting a program when it is closed could stop some processing of the program that you don't want to stop. Just to go further what I said, check this : http://stackoverflow.com/questions/922207/how-can-i-make-a-program-thats-impossible-to-be-killed-in-windows – Quentin S. May 18 '17 at 13:11
0

AntiVirus software also achieves that. I just don't know how they do that exactly. But you should start with running your program as a service. That makes it quite difficult already for average users.

Then find out how to avoid that the service is stopped. I think you also need to run it under the system user account.

If you need a GUI for administration, then you should write a 2nd program that communicates with your service.

Here' some info how to (try to) kill an unstoppable service:
https://superuser.com/questions/338539/how-to-stop-an-unstoppable-windows-7-service/338560
So that's the opposite of what you want to achieve. Meaning, if your service stands all of these attacks, you have succeded.

After some Internet search I found these (the results 1 to 5, and 8, in searching for "c# create service avoid stopping"):
Prevent Windows service manager from stopping a service c#
Protecting a Windows Service from untrusted users
(Stop Windows Service and avoid time out warning message)
https://social.msdn.microsoft.com/Forums/vstudio/en-US/95ab8bf4-fa18-4f37-8a92-dc0b346afb76/prevent-a-user-from-killing-a-windows-service?forum=csharpgeneral
https://msdn.microsoft.com/en-us/library/9k985bc9(v=vs.110).aspx
http://www.csharp-examples.net/restart-windows-service/

Community
  • 1
  • 1
Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45