2011-01-30 2 views
0

C# 프로그램을 사용하여 컴퓨터를 종료/최대 절전 모드/재시작/절전 모드로 전환 할 수 있습니까? 종료/재부팅 시스템 사용에C# shutdown/hibernate/sleep

답변

3

-

using System.Management; 

    void Shutdown() 
    { 
     ManagementBaseObject mboShutdown = null; 
     ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem"); 
     mcWin32.Get(); 

     // You can't shutdown without security privileges 
     mcWin32.Scope.Options.EnablePrivileges = true; 
     ManagementBaseObject mboShutdownParams = 
       mcWin32.GetMethodParameters("Win32Shutdown"); 

     // **Flag 1 means we want to shut down the system. Use "2" to reboot**. 
     mboShutdownParams["Flags"] = "1"; 
     mboShutdownParams["Reserved"] = "0"; 
     foreach (ManagementObject manObj in mcWin32.GetInstances()) 
     { 
      mboShutdown = manObj.InvokeMethod("Win32Shutdown", 
              mboShutdownParams, null); 
     } 
    } 

more here

최대 절전 모드 및 대기 - 당신이 .NET 2.0을 사용하는 경우 당신은 그냥 Application.SetSuspendState를 호출 할 수 있습니다.

Check out the documentation at:

1
Process.Start("shutdown", "/s /t 0"); // shutdown 
Process.Start("shutdown", "/r /t 0"); // shutdown and restart 
Process.Start("shutdown", "/h /f"); // hibernate