Disabling Windows Sleep and Hibernation From Your Kiosk Application

Disabling Windows Sleep and Hibernation From .NET WPF C#In this article I’ll explain how to disable the Windows Sleep and Hibernation Power Options directly from your kiosk application.  Imagine the scenario where your kiosk goes to sleep and potential customers see nothing but a black screen.  Many customers will assume the kiosk is out of order and keep right on walking.  To make matter worse, when the user touches the screen they’ll be greeted by a Windows login prompt and chances are they won’t know the password.

This is the scenario we’re trying to avoid by disabling the Windows sleep and hibernation functionality.  Sure you could go to the Power Options and disable sleep and hibernation completely but then you’d have to do that on ever single kiosk.  It would be more convenient to temporarily disable sleep and hibernation only while your kiosk application is running.

Fortunately Microsoft has included support for disabling the Windows Sleep and Hibernation Power Options via the SetThreadExecutionState function.

In the case of my kiosk application (a native Windows application written in .NET WPF C#) I simply define a timer that periodically calls SetThreadExecutionState and passes in the System Required attribute which forces Windows to be in a working state by resetting the system idle timer.  This ensures that the Windows sleep and hibernation functions will be temporarily disabled regardless of the Power Options while my kiosk application is running.

SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED); // Reset the system idle timer

When your kiosk application is closing you should call SetThreadExecutionState one last time and pass the continuous attribute to allow the system to go idle again.

SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS); // Allow the system to go idle again

I also recently wrote an article on Disabling the Windows Screen Saver From Your Kiosk Application.  All of this functionality comes standard with KioskSimple if you don’t want to roll your own.  KioskSimple also prevents your kiosk from powering off the display when the system is idle and blocks system keystrokes like Ctrl-Alt-Del and generally secures your kiosk application.  Try an a free demo of KioskSimple today!


Andrew Savala
Follow me

Author: Andrew Savala

Andrew Savala is the CEO of RedSwimmer, with a background in designing and deploying complex payment kiosk systems. Andrew offers high-value, strategic consulting services to companies looking to develop their payment kiosks.