Application的OnSessionEnding, 是在Windows关机或登出的时候触发 因此继承Application并 override OnSessionEnding,就可以做到取消关机或登出 using System; using System.Windows; using System.Windows.Input; namespace Cloud.InheritApp { class InheritTheApp : Application { [STAThread] public static void Main() { InheritTheApp app = new InheritTheApp(); app.Run(); } protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Window win = new Window(); win.Title = "Cloud inherit Application"; win.Show(); } protected override void OnSessionEnding(SessionEndingCancelEventArgs e) { base.OnSessionEnding(e); MessageBoxResult result = MessageBox.Show("Close?", MainWindow.Title, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK); e.Cancel = (result == MessageBoxResult.OK); } } }