我希望我的应用程序可以防止 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.
}
}
并且也使用此代码,但不起作用:(:
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.
}
如果有人向我解释如何“取消”Windows关闭,我将不胜感激。谢谢