Keep a Windows machine awake
Executable binaries for Windows may be found at the Releases page.
The executable stay-awake.exe
is intended to be run in a terminal in order to keep one's Windows machine awake.
There are two modes one may choose from:
- System [Default] → the machine will not go to sleep but the display could turn off
- Display → the machine will not go to sleep and the display will remain on
The simplest use case is to run the executable without any switches.
stay-awake.exe
This will prevent the machine from going to sleep and will await the user pressing the Enter
key within the terminal before resetting the machine state.
To keep the machine awake and prevent the display from turning off, utilize the --display
switch.
stay-awake.exe --display
This will prevent the machine from going to sleep (while also keeping the display on) and will await the user pressing the Enter
key within the terminal before resetting the machine state.
📝 As noted in the Win32 documentation, use of the
SetThreadExecutionState
function (which is the Win32 function called bystay-awake.exe
) does not prevent one from putting their computer to sleep by either closing the lid on their laptop or pressing the power button. In addition, the screen saver may still execute.
Result of running stay-awake.exe --help
stay-awake
Keep a Windows machine awake
USAGE:
stay-awake.exe [OPTIONS]
OPTIONS:
--display Keep display on
-h, --help Print help information
-V, --version Print version information
In order to test, open PowerShell with elevated (admin) privileges. After executing the program, run the following.
powercfg -requests
Application utilizes SetThreadExecutionState from the Win32 API.
C#
Rust
- Loads
kernel32.dll
and performs a transmute to get the function SetThreadExecutionState
- Loads
- Microsoft PowerToys includes the Awake utility
- It also utilizes SetThreadExectionState to keep a Windows machine awake