How do I stop my computer from going into sleep or hibernate mode?

For application - you may want to look at win32 function SetThreadExecutionState

Anyway, you could set different power scheme in windows control panel to let computer stay awake all the time.


You've got several events to handle to acheive this. First up, process the WM_SYSCOMMAND message, specifically the SC_SCREENSAVE and SC_MONITORPOWER options. Secondly, handle the WM_POWERBROADCAST message and return BROADCAST_QUERY_DENY.

However, MS decided to allow the BROADCAST_QUERY_DENY to be ignored by the system so it'll only work where it's allowed to work, usually a user setting. Too many applications were preventing power-down that the feature was effectively redundant.

Skizz


Have a look at insomnia, which if I understand correctly is exactly the application you want. Note that both binary and source code are available, so if you prefer to roll your own, you can use that as a starting point.