I have a client app that needs to be up 24/7. I’m looking for any way to detect if a Windows computer is going to to go Sleep, Hibernation, Shutdown, Restart, or Suspend mode (did I get all the permutations?). In the ideal world I want to be able to keep that from happening.
I looked at the WindowsPowerStateMBS class from MBS and it doesn’t appear to work as advertised (at least in Windows 8.1). Anyone have any ideas/suggestions to look at?
Well, WindowsPowerStateMBS is made to detect shutdown/sleep, so app can do things just before system goes to sleep.
You may need to configure windows manually to not go to sleep.
The easiest solution would be to set the power management options such that the computer will not go to sleep, or otherwise turn itself down. It is pretty easy to do, but it requires that you know in advance and have an admin access to the computer.
In the run text box, type powercfg.cpl and press enter. You now have access to the power management options and can prevent disk spin-off, screen out, sleep, etc. You can also access the settings through the control panel.
'if vista or newer (use your own method to determine windows version)
result = setThreadExecutionState(ES_CONTINUOUS or ES_SYSTEM_REQUIRED or ES_AWAYMODE_REQUIRED)
'if xp
'result = setThreadExecutionState(ES_CONTINUOUS or ES_SYSTEM_REQUIRED)[/code]