
nosleep-server
Windows CLI utility (server) that prevents the computer from entering sleep.
The server will prevent the computer from going to sleep by setting SetThreadExecutionState.
The client will communication via RPC with the server to change the sleep mode or shutdown
the server.
The main use case is to prevent sleep during a long running task:
- start
nosleep-server in the background
- run task (eg. backup script)
- nosleep-client calls server with shutdown request
It's important to note that SetThreadExecutionState only applies to the current thread, so
this server runs an ExecStateManager that is locked to a single OS thread. The RPC server
uses this ExecStateManager to ensure consistent state accross calls.
Install
go install github.com/tischda/nosleep-server@latest
Usage
Usage: nosleep-server [OPTIONS]
Sets ThreadExecutionState to (ES_CONTINUOUS | ES_SYSTEM_REQUIRED) and
starts an RPC server on ADDRESS:PORT (default: 127.0.0.1:9001).
You can manage the server using RPC calls to control thread execution states
where possible commands are: Clear, Display, System, Critical, Read and Shutdown.
Another way to control the server is by registering/unregistering processes.
The server will automatically shut down when the last process is unregistered.
OPTIONS:
-n, --network string
Network type: tcp, tcp4, tcp6, unix or unixpacket (default "tcp")
-a, --address string
Bind address (default 127.0.0.1)
-p, --port int
RPC server listening port (default 9001)
-d, --display
Force display to stay on
-l, --log path
Write logs to a file instead of stdout
-?, --help
displays this help message
-v, --version
print version and exit
Examples
nosleep-server --port 9015 --display
will set ThreadExecutionState to (ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED)
and start an RPC server listening on 127.0.0.1:9015.
You can test the result like this (requires admin rights):
❯ powercfg -requests
DISPLAY:
None.
SYSTEM:
[PROCESS] \Device\HarddiskVolume5\src\go\nosleep-server\nosleep-server.exe
AWAYMODE:
None.
EXECUTION:
None.
PERFBOOST:
None.
ACTIVELOCKSCREEN:
None.
References