Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

setsuspendstate (powrprof)
 
.

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:

.Net 2.0 provides this managed method with identical arguments:

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

VB.net example .20 , .Net 3.5

    Application.SetSuspendState(PowerState.Hibernate, False, False)
    'Or
    Application.SetSuspendState(PowerState.Suspend, False, False)

Public Shared Function SetSuspendState(ByVal state As System.Windows.Forms.PowerState, ByVal force As Boolean, ByVal disableWakeEvent As Boolean) As Boolean

     Member of System.Windows.Forms.Application

Summary:

Suspends or hibernates the system, or requests that the system be suspended or hibernated.

Parameters:

state: A System.Windows.Forms.PowerState indicating the power activity mode to which to transition.

force: true to force the suspended mode immediately; false to cause Windows to send a suspend request to every application.

disableWakeEvent: true to disable restoring the system's power status to active on a wake event, false to enable restoring the system's power status to active on a wake event.

Return Values:

true if the system is being suspended, otherwise, false.

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions