This is a small tool that allows you to prevent a Windows machine from sleeping/hibernating. This is useful, for example, when connecting over SSH to a Windows machine that is configured to sleep when not used.
Unlike other solutions to this task, keep-awake doesn't change global computer settings and so doesn't leave
them 'orphaned' if it is abnormally terminated.
Just drop keep-awake.exe for your architecture from Releases
anywhere on your %PATH%.
keep-awake is a command-line application that works by launching a background copy of itself
which prevents the computer from sleeping.
This allows you to continue your work while it is running in background.
You can see the available command line options by running keep-awake --help
This mode is useful when connecting over SSH. Windows SSH server kills all the child processes created within SSH session when the session ends. Thus, effectively, this mode keeps the computer alive while the session is active.
keep-awake
... other commands ...You can pass an optional timeout argument to keep-awake (see below for syntax).
If not running over SSH:
keep-awake <timeout>
... other commands ...When running over SSH you can prevent keep-alive process from being killed when SSH session ends using:
- If your shell is CMD
powershell -Command "Invoke-WmiMethod -Path 'Win32_Process' -Name Create -ArgumentList 'path\to\keep-awake <timeout>'"- If your shell is Powershell
Invoke-WmiMethod -Path 'Win32_Process' -Name Create -ArgumentList 'path\to\keep-awake <timeout>'The syntax for <timeout> can be a single number - this is interpreted as seconds.
Or, you can use a full format:
"<num>d <num>h <num>m <num>[s]"
For days, hours, minutes and seconds. Every part is optional, but at least one must be present.
You can use any number of spaces (including none) anywhere in the string but, if you do, you will need to
wrap the string in " to make it one command line argument.
You can list currently active background instances of keep-awake and how long they have left
to run.
keep-awake list
You can stop running instances of keep-awake via:
keep-awake stop pid [pid ...]
where pid is a process ID of a running instance. The process IDs are reported when you launch keep-awake
or by list command.
Alternatively, you can always terminate an instance using Task Manager or a similar tool.
Since version 2.1.0 keep-awake supports colored output if the output is printed on a terminal that supports
colors. You can override this behavior using environment variables NO_COLOR and
FORCE_COLOR. If both are set NO_COLOR takes precedence.
Clone this repository and open its folder in Visual Studio 2022 or later as a CMake project.