A lightweight Rust utility to keep Windows awake.
Rust Never Sleep is a small command-line program written in Rust that prevents Windows from automatically entering sleep mode.
It interacts directly with the Windows API through the winapi crate, using SetThreadExecutionState to tell the system to stay active.
- Keeps the system and display awake for a given duration.
- Accepts user input in seconds.
- Defaults to 14 minutes when no input is provided.
- Handles invalid input (non-numeric or zero) gracefully.
- Uses structured logging (
info,warn,error) vialog+env_logger. - Simple to build, simple to run — no dependencies beyond Rust itself.
- 🪟 Windows OS
- 🦀 Rust toolchain (Install here)
- Cargo (included with Rust)
-
Clone the repository:
git clone https://github.com/jabibamman/rust-never-sleep.git cd rust-never-sleep -
Build the project in release mode:
cargo build --release
-
The compiled binary will be located at:
target/release/rust-never-sleep.exe
Run the executable directly or through a terminal:
./rust-never-sleep.exeYou will be prompted:
Enter sleep duration in seconds or press Enter for default (14 minutes):
Examples:
- Press Enter → uses the default duration of 14 minutes.
- Enter
600→ keeps the system awake for 10 minutes. - Enter
0or any invalid text → prints an error and asks again.
To stop the program, simply close the terminal window.
rust-never-sleep uses the log crate with env_logger for runtime logging.
By default, logs are shown at the info level.
You can change this by setting the environment variable RUST_LOG:
$env:RUST_LOG="debug"
./rust-never-sleep.exeAvailable levels: error, warn, info, debug, trace.
- Language: Rust
- Target:
x86_64-pc-windows-gnu - Windows API used:
SetThreadExecutionState- Flags:
ES_CONTINUOUS,ES_DISPLAY_REQUIRED,ES_SYSTEM_REQUIRED,ES_AWAYMODE_REQUIRED
- Flags:
- Error Handling:
- Input errors are logged and retried.
- Windows API failures are logged using
std::io::Error::last_os_error().
- Designed exclusively for Windows systems.
- Ensure the use of this utility aligns with your organization’s policies.
- While running, the program prevents automatic sleep and display timeout events.
Contributions are welcome!
If you’d like to improve the code, fix issues, or add features, please open a Pull Request.
MIT License © 2025 James Abib