Most of Antivirus applications will prevent you from closing them in task manager, Kaspersky is a real example.
What did they do to limit permissions, even for administrators, to prevent terminating their program?.
Generally speaking, there's no way to stop your process from being terminated by a user with permission to do so.
So, if the user is not an administrator it would suffice to run the process in a different user context (eg run it as a service).
As mentioned in this article "you can not, and should not, attempt to stop an Administrator from killing your process or stopping your service".
That being said, you can adjust your process’ access control list to prevent users from killing it.
It is a good practice to explicitly give the necessary rights and not let everybody (user or application) have administrative rights in your system.
Using this practice you can easily prevent nearly everyone from terminating your process.
You can find here more information about the Microsoft Windows security model and options about securing your application against the world.