[API]
ExitWindowsEx
SetSystemPowerState
SendMessageA

[INCLUDE]
AquirePrivilege

[DEFINE]
Public Enum ShutDownWindowsEx_Mode
  SDWE_Shutdown = 1
  SDWE_Hibernate = 2
  SDWE_Standby = 3
  SDWE_MonitorsOff = 4
  End Enum

[CODE]
Public Function ShutdownWindowsEx(ByVal Mode As ShutDownWindowsEx_Mode) As Boolean
  Call AquirePrivilege("SeShutdownPrivilege")
  Select Case Mode
    Case SDWE_Shutdown
      ShutdownWindowsEx = Not (ExitWindowsEx(9&, 0&) = 0&)
    Case SDWE_Hibernate
      On Error Resume Next
      ShutdownWindowsEx = SetSystemPowerState(1&, 0&)
      On Error GoTo 0
    Case SDWE_Standby
      On Error Resume Next
      ShutdownWindowsEx = SetSystemPowerState(0&, 0&)
      On Error GoTo 0
    Case SDWE_MonitorsOff
      ShutdownWindowsEx = SendMessageA(-1&, &H112&, &HF170&, byval 1&)
    End Select
  End Function
