我首先会拦截负责的事件 当前关闭的会议 并附加一个事件处理程序，然后从那个事件中，我会检查是否检查了您的小复选框，如果检查（true），那么您可以尝试 AbortSystemShutdownA通过这个电话 拦截然后取消关机过程。您还可以在有关文档中找到更多信息 关闭事件。这也可以使用 Pinvoke.. - Search Shutdown on the Pinvoke page. If you have a specific question regarding implementing any of these events, post up what you've tried and we can try to help you from there.
The e.Cancel = true; will prevent your application from closing, but if someone tries to log off, only your application will prevent windows from logging off. You should note; it won't stop the closure of other applications on the system while the logoff is commencing. When windows shuts down, it collects a list of running applications in need of being closed before the log off can commence. Depending on the order of the opened applications being cued for closure, whatever applications are cued before yours, will also be closed regardless of your applications current state, and windows will only halt when your application is being processed. Any applications cued after your application will also not be shut down. However, a user can still persist to ignore your applications state and force the log off to continue by way of interacting with log off screen. See pic :
我可以考虑完全防止关机的唯一方法是（如果可能）更改一些安全策略以防止用户组能够手动注销。这不是我以前尝试过的东西，但可能有可能。 根据这个, there is an option to remove the button from the Start menu. So in theory, you could include using Microsoft.GroupPolicy; and get to work on rewriting the registry values. But yuck, and I would highly recommend you backup your registry in full before playing with a major part of the operating system if you're on a development machine or not. The Microsoft.GroupPolicy will give you much more control over a users ability to log off VIA the UI, but if they know how to reboot and log off via cmd, you may have a new problem on your hands to prevent that. Some here might argue that group policy might not be the best way to go about it.