SetSuspendState (powrprof)
Last changed: zkonstantin3@gmail.com-86.57.255.92

.

Suspends the current machine.

If hibernate = true, the system hibernates.

If hibernate = false, the system enters a standby state.

C# Signature:

[DllImport ("Powrprof.dll", SetLastError = true)]

static extern bool 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 Boolean

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

using System;

using System.Runtime.InteropServices;

namespace Sleeper

{

    class Class1
    {
        [DllImport ("Powrprof.dll", SetLastError = true)]
        static extern bool SetSuspendState (bool hibernate, bool forceCritical, bool disableWakeEvent);
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            // make the computer go to sleep.
            SetSuspendState (true, false, false);
        }
    }

}

VB.Net

Public Class Form1

    Inherits System.Windows.Forms.Form

    'SetSuspendState will put the PC in to a standby mode
    Private Declare Function SetSuspendState Lib "powrprof.dll" (ByVal Hibernate As Boolean, ByVal ForceCritical As Boolean, _
    ByVal DisableWakeEvent As Boolean) As Boolean

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'SetSuspendState Example
    '*************************************************************************************************
    'SetSuspendState(False, False, False)
    '*************************************************************************************************

    End

    End Sub

Alternative Managed API:

System.Windows.Forms.Application.SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent)

Documentation