我想我的应用程序可以防止Windows关闭.我知道有一个系统命令来做到这一点.但不适合我的计划.我使用此代码"取消"窗口关闭:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason.Equals(CloseReason.WindowsShutDown))
{
MessageBox.Show("Cancelling Windows shutdown");
string cmd = "shutdown /a";
Process.Start(cmd);// for executing system command.
}
}
Run Code Online (Sandbox Code Playgroud)
并使用此代码,但不起作用:(:
public Form1()
{
InitializeComponent();
SystemEvents.SessionEnding += SessionEndingEvtHandler;
}
private void SessionEndingEvtHandler(object sender, SessionEndingEventArgs e)
{
MessageBox.Show("Cancelling Windows shutdown");
string cmd = "shutdown /a";
Process.Start(cmd);// for executing system command.
}
Run Code Online (Sandbox Code Playgroud)
如果有人解释我怎么能在"取消"关闭窗口,我将不胜感激.谢谢