用VS做的C#应用程序,调用系统关机的代码应该怎么写?

解决方案 »

  1.   

    public   enum   ExitWindows   :   uint   
      {   
            LogOff   =   0x00,   
            ShutDown   =   0x01,   
            Reboot   =   0x02,   
            Force   =   0x04,   
            PowerOff   =   0x08,   
            ForceIfHung   =   0x10   
      }   
        
        
        
      [DllImport("user32.dll")]   
                      static   extern   bool   ExitWindowsEx(ExitWindows   uFlags,   ShutdownReason   dwReason);   
        
        
                      [STAThread]   
                      static   void   Main(string[]   args)   
                      {   
                              ExitWindowsEx(ExitWindows.LogOff,   ShutdownReason.MajorOther   &   ShutdownReason.MinorOther);     
                              
                      } 
      

  2.   

    //使用cmd的定时关机
    private void button1_Click(object sender, EventArgs e) 

    if (DateTime.Now.Hour == int.Parse(comboBox1.Text) && DateTime.Now.Minute == numericUpDown2.Value) 

    msg=MessageBox.Show("您现在就要关机吗?建议先取消,设置具体时间关机!", "温馨提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); 
    if ( msg== DialogResult.Yes) 

    System.Diagnostics.Process.Start("cmd.exe", "shutdown -f -s -t 1"); //强制一秒倒计时关机! 

    else 
    return; 
      

  3.   

    我觉得你可以调用命令行shutdown -s