解决方案 »

  1.   

    重写OnFormClosingprotected override void OnFormClosing(FormClosingEventArgs e)
      {
       switch (e.CloseReason)
       {
        case CloseReason.ApplicationExitCall:
         e.Cancel = true;
         MessageBox.Show("拦截关闭要求事件!");
         break;
        case CloseReason.FormOwnerClosing:
         e.Cancel = true;
         MessageBox.Show("拦截自身关闭事件!");
         break;
        case CloseReason.MdiFormClosing:
         e.Cancel = true;
         MessageBox.Show("拦截MDI窗体关闭事件!");
         break;
        case CloseReason.None:
         break;
        case CloseReason.TaskManagerClosing:
         e.Cancel = true;
         MessageBox.Show("拦截任务管理器关闭事件!");
         break;
        case CloseReason.UserClosing:
         e.Cancel = true;
         MessageBox.Show("拦截用户关闭事件!");
         break;
        case CloseReason.WindowsShutDown:
         e.Cancel = true;
         MessageBox.Show("拦截关机事件!");
         break;
        default:
         break;
       }   base.OnFormClosing(e);
      }参见:http://www.cnblogs.com/ajiefj/archive/2010/05/11/1732419.html
      

  2.   

    既然是监测 那么肯定得是window服务了..开机好说.关机没电了你怎么检测..select * from win32_xxoo  估计可以查询到吧...具体google下
      

  3.   


    C:\Windows\System32\shutdown.exe -s -t 0
      

  4.   

    直接搜C#关机代码就 一大堆Process myProcess = new Process();//定义一个线程实例;
    myProcess.StartInfo.FileName = "cmd.exe";//启动名为"cmd.exe"的线程,就相当于你点击电脑左下角的"开机"-"运行"-输入cmd后回车,也就是启动了命令提示符界面;
    myProcess.StartInfo.UseShellExecute = false;//关闭Shell的使用
    myProcess.StartInfo.RedirectStandardInput = true;//重定向标准输入
    myProcess.StartInfo.RedirectStandardOutput = true;//重定向标准输出
    myProcess.StartInfo.RedirectStandardError = true;//重定向错误输出
    myProcess.StartInfo.CreateNoWindow = true;//设置不显示窗口
    myProcess.Start();//此处才是启动了该线程
    myProcess.StandardInput.WriteLine("shutdown -s -t 0");//相当于你在命令提示符界面输入"shutdown -s -t 0"