Search code examples
windowswinapishutdownpower-management

User's Preferred poweroff action - Windows


I have a program that takes a long time to run and is intended to run unattended. In Windows, what is the best way to determine the users preferred poweroff action.

  • What the power button does.
  • In Windows 7, the start menu logoff action (Which is Shut Down by default).

How can I determine these values on Windows XP, Windows Vista and Windows 7?

Is there an API to do this? (i.e. Shutdown, Suspend, or Hibernate according to users preferences)


Solution

  • If you are using managed code, there is PowerGetActiveScheme. There is an example of how to use it here: http://www.pinvoke.net/default.aspx/powrprof.powergetactivescheme