Expand Minimize

SetSystemPowerState function

[SetSystemPowerState is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Applications written for Windows Vista and later should use SetSuspendState instead.]

Suspends the system by shutting power down. Depending on the ForceFlag parameter, the function either suspends operation immediately or requests permission from all applications and device drivers before doing so.

Syntax


BOOL WINAPI SetSystemPowerState(
  _In_  BOOL fSuspend,
  _In_  BOOL fForce
);

Parameters

fSuspend [in]

If this parameter is TRUE, the system is suspended. If the parameter is FALSE, the system hibernates.

fForce [in]

This parameter has no effect.

Windows Server 2003 and Windows XP:  If this parameter is TRUE, the function broadcasts a PBT_APMSUSPEND event to each application and driver, then immediately suspends operation. If the parameter is FALSE, the function broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation.

Return value

If power has been suspended and subsequently restored, the return value is nonzero.

If the system was not suspended, the return value is zero. To get extended error information, call GetLastError.

Remarks

The calling process must have the SE_SHUTDOWN_NAME privilege. To enable the SE_SHUTDOWN_NAME privilege, use the AdjustTokenPrivileges function. For more information, see Changing Privileges in a Token.

If any application or driver denies permission to suspend operation, the function broadcasts a PBT_APMQUERYSUSPENDFAILED event to each application and driver. If power is suspended, this function returns only after system operation is resumed and related WM_POWERBROADCAST messages have been broadcast to all applications and drivers.

This function is similar to the SetSuspendState function.

To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information, see Using the Windows Headers.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Power Management Functions
PBT_APMQUERYSUSPEND
PBT_APMQUERYSUSPENDFAILED
PBT_APMSUSPEND
SetSuspendState
WM_POWERBROADCAST

 

 

Community Additions

ADD
Show:
© 2014 Microsoft