Prevent Windows Application (VB.Net)Termination

ε祈祈猫儿з 提交于 2020-01-23 17:36:08

问题


I have the need to either prevent, or restrict, the termination of a VB.Net application. I have no problem with Admin killing the application, but not a user. I've been unable to come up with a solution for this. Is there maybe even a way to set local policy to prevent termination by non-admin?

Note: I've seen this question asked before and people ask "why", assuming this is for a malicious purposes. This is a GUI app that MUST remain on top of the users windows per policy.

Update: I know this is possible SOMEHOW... I have seen applications that, when I try to terminate them through the task manager, I get a permission denied. That's what I'm trying to do...


回答1:


If you handle formclosing event and say e.cancel if it is a normal user then it will be handled in your boundary. But you cannot enforce policy until and unless there is physical restriction applies in windows. I feel if you can remove the .NET keyword and put the question to IT specific guys it will help. In .NET you can do other than what I have explained in the initial statement.




回答2:


The following code will stop your form from closing (and should therefore stop your application closing) when the user hits the red X in the corner:

Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    If e.CloseReason = CloseReason.UserClosing Then e.Cancel = True
End Sub

You can't stop someone running task manager and killing the process though, but you can stop them from running task manager using group policy



来源:https://stackoverflow.com/questions/10083302/prevent-windows-application-vb-nettermination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!