I'm trying to keep my Windows PC from sleeping when I'm connected to WSL via SSH, but I want this to be a temporary solution. The challenge is that if multiple clients connect and the first one disconnects, I don't want my PC to automatically go to sleep. Here's what I've tried so far:
- I used `SetThreadExecutionState`, but it only works with the `ES_CONTINUOUS` flag, which is frustrating.
- I attempted Powertoys Awake, but the CLI didn't work at all for me, and I doubt that running it multiple times would be effective since there's little documentation available.
- I also tried sending simulated key presses, like F15 or Caps Lock every 10 seconds, but my system is still going to sleep, even though I've seen others say that this method works.
I also explored other options but they don't fit my requirement of being temporary, like using `powercfg` or `SetThreadExecutionState` with the `ES_CONTINUOUS` flag. Honestly, I'm pondering switching to Linux since I haven't been gaming much lately, but I'm baffled as to why this is turning out to be so difficult!
3 Answers
It sounds like you're facing quite a task! Have you considered why you want to keep your system temporarily awake? Maybe pinpointing the exact reason can help you find a tailored solution. Just a thought!
If you're not using `ES_CONTINUOUS`, you'll need to call `SetThreadExecutionState` frequently to reset the idle timer. Remember, without that flag, it’s not going to keep the system awake for long periods. It's a bit of a hassle, but it might just do the trick!
Why not just disable sleep completely? You mentioned you still want your PC to sleep when it's not in use. I'm curious, though, what's the Linux solution you heard about? I've heard `systemd-inhibit` works really well for keeping the system from going to sleep in Ubuntu!
Yeah, I want it to sleep since it's mostly unused. I read that `systemd-inhibit` in Ubuntu is a pretty slick way to manage that sleep issue. Here's a link I found with more info: https://askubuntu.com/a/1382999
Good point! I think I remember a thread discussing how `SetThreadExecutionState` behaves without that flag – here's a link for more context: https://stackoverflow.com/questions/72436579/setthreadexecutionstatees-system-required-does-not-prevent-system-sleep-on-win