SetSuspendState
C# Signature:
[DllImport ("Powrprof.dll", SetLastError = true)]
static extern uint SetSuspendState (bool hibernate, bool forceCritical, bool disableWakeEvent);VB Signature:
Declare Function SetSuspendState Lib "powrprof.dll" (ByVal Hibernate As Boolean, ByVal ForceCritical As Boolean, ByVal DisableWakeEvent As Boolean) As BooleanSample Code:
using System.Runtime.InteropServices;
namespace Sleeper
{
class Program
{
/// <summary>
/// Suspends the system by shutting power down. Depending on the Hibernate parameter, the system either enters a suspend (sleep) state or hibernation (S4).
/// </summary>
/// <param name="hibernate">If this parameter is TRUE, the system hibernates. If the parameter is FALSE, the system is suspended.</param>
/// <param name="forceCritical">Windows Server 2003, Windows XP, and Windows 2000: If this parameter is TRUE,
/// the system suspends operation immediately; if it is FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to each
/// application to request permission to suspend operation.</param>
/// <param name="disableWakeEvent">If this parameter is TRUE, the system disables all wake events. If the parameter is FALSE, any system wake events remain enabled.</param>
/// <returns>If the function succeeds, the return value is true.</returns>
/// <remarks>See http://msdn.microsoft.com/en-us/library/aa373201(VS.85).aspx</remarks>
[DllImport("Powrprof.dll", SetLastError = true)]
static extern uint SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent);
static void Main(string[] args)
{
// Sleeps the machine
SetSuspendState(false, false, false);
}
}
}Sample Code:
Sample Code:
Sample Code:
Alternative Managed API:
Alternative Managed API:
Última actualización