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. }
SessionEndingEvtHandler
e.Cancel = true;
public Form1() { InitializeComponent(); SystemEvents.SessionEnding += SessionEndingEvtHandler; } private void SessionEndingEvtHandler(object sender, SessionEndingEventArgs e) { e.Cancel = true; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)