Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am a .net programmer, i need a soln, am creating a windows application, i want to prevent my application by killing application process from the task manager. Like when we try to kill a windows process, anyone have any idea plz comment me
Posted
Comments
M.Edmison 14-Jan-13 15:06pm    
I would recomend from reading the above posts, to maybe have a scheduled task or something of the sort that looks to see if the process is not running then start it.

Meaning, sure they can close it but you can just open it back up again.

Depending on the need for this may or may not be useful. (repost for options to original question)

[In addition to the correct answer by ProgramFOX]

I also want to explain why it's not possible to prevent the application process from killing through the Task Manager. In brief, this is because Task Manager is the last line of defense for a user.

Let's imagine for a minute that such feature is implemented in the OS, which would be technically quite possible. Let's assume this is related to application processes only, nothing executed in the kernel ring. Even in this case, it would be easy to block the operation of the whole system forever, more exactly, until the user boots from a different media and re-install the OS or modifies it.

The OS is designed the way that the application process cannot really hang it. But still, it can screw up the OS functionality pretty well; for example, it can consume too much of resources and never stop. Even though the OS might be not hanging, but it will be practically unusable. And it does not matter if it's done accidentally or not; the system is still not usable. The only way to fix it would be the Task Manager or similar tool, but you want to prevent it. Worse, you can easily make your offending process auto-started when the OS starts or the user logs in. This way, you would completely block the possibility to fix the problem caused by a bad application. This is too costly to allow it happen.

—SA
 
Share this answer
 
Hi,

It's not possible to prevent that a user kills your process using the "End Process" button. You can only cancel that your application will be closed if the user uses the "End Task" button:
C#
public Form1()
{
    InitializeComponent();
    this.FormClosing += Form1_FormClosing;
}
void Form1_FormClosing(object sender, FormClosingEventArgs e)
       {
           if (e.CloseReason == CloseReason.TaskManagerClosing) // if the user tries to closes the process using the "End task" button in task manager, cancel this
           {
               e.Cancel = true;
           }
       }

Hope this helps.
 
Share this answer
 
Comments
fjdiewornncalwe 14-Jan-13 13:33pm    
My 5.
Thomas Daniels 14-Jan-13 13:34pm    
Thank you!
Sergey Alexandrovich Kryukov 14-Jan-13 14:25pm    
I also tried to explain why is it so. Please see my answer.
This answer is of course credited.
—SA
Sandeep A K 14-Jan-13 13:35pm    
sir,
what will happen if the user right click my application process and click the end process? will my application exit?
Thomas Daniels 14-Jan-13 13:38pm    
Yes. There's no way to prevent that. You can only prevent closing your application if the user uses the "End Task" button, and not the "End Process" button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900