SetSystemPowerState function (winbase.h)

[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 SetSystemPowerState(
  [in] BOOL fSuspend,
  [in] BOOL fForce
);

Parameters

[in] fSuspend

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

[in] fForce

This parameter has no effect.

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

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winbase.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See also

PBT_APMQUERYSUSPEND

PBT_APMQUERYSUSPENDFAILED

PBT_APMSUSPEND

Power Management Functions

SetSuspendState

WM_POWERBROADCAST