There is no direct way to avoid the standard behavior of Windows. A Windows user should be able to kill applications. If the application does not obey, the system forcibly kills the application.
However, there are a few tricks often used by virus writers, here are some (not extensive) ones:
- Disabling all system hot keys is relatively trivial, but Ctrl-Alt-Del is not one of them. Check out this excellent code project article with a sample application.
- Create a DLL and add yourself to other processes that are vital to the system. Ease of execution, but make sure that you port the application from .NET to stand-alone C ++ or another language, you do not want the system processes to depend on the version of .NET you are loading.
- Instead of a dll sentence, you can create something like a shell extension with a library like this one that allows you to continue to use. NETWORK. It is not intended for this kind of thing, but it forces the user to kill
explorer.exe to get rid of your application. - Create a service that can interact with the desktop. Limit the rights of the service by conventional means, which essentially has the same effect as preventing users from killing your application using the methods you mention.
- Obviously, you should cancel any message
WM_CLOSE , WM_EXIT or WM_KILL and just continue to live. - Use a desktop application, this is what most anti-virus scanners use: if you kill one process, the sentinel will restart it. If you kill the sentry, it should be restarted in the main application. Bad behavior, but it works.
But, general advice: do not do this. Allow your users to potentially kill the program if necessary, otherwise it will be very difficult to perform any maintenance. The only "supported" way is services where you can allow special users to stop your service and cannot be stopped through the task manager.
source share