简体   繁体   中英

Password Protect Winforms Application

I have a simple WinForms application that runs in the system tray. Is it possible to password protect the program from closing if a user tries to close it from task manager?

Ideally I want to keep a user from closing the process but if windows is restarted, I want it to close without being prompted. Much like antivirus programs.

If a user has the correct permissions they will be able to kill your process from the Task Manager.

That said as @fujiFX mentions in his comment the FormClosing event is a good start and better than nothing.

The FormClosing event occurs as the form is being closed. When a form is closed, it is disposed, releasing all resources associated with the form. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel property of the FormClosingEventArgs passed to your event handler to true .

It's hard to do, but you can create two applications, one is main program and two is helper. If helper is killed, then main app restarts it. If main app is killed, then helper restarts main app.

您可以在YourService.Stop方法上进行此验证(假设您使用的是从ServiceBase继承的Windows服务),但据我所知,您无法阻止用户终止进程,只是为了关闭应用程序(两个不同的东西)在Windows中)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM