0

I've been tasked with writing a Windows script that does a number of things, including preventing Windows from sleeping.

I've already tried Window's SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS) to no avail. It seems that some group policy is enforcing the sleep timer. I know of others here that run a powerpoint presentation in the background to prevent the screen from sleeping but I'm looking for the more elegant (programmatic) solution here.

Another key functionality of the script is listening for input to determine an idle state, and then locking the computer upon interruption of said idle state. Therefore, I cannot just toggle the numlock occasionally or something like that.

Any insight is GREATLY appreciated.

Sean Weber
  • 21
  • 1
  • You can go one step beyond and use `ES_SYSTEM_REQUIRED`, rather than just `ES_DISPLAY_REQUIRED`. Also, you must make sure to keep the thread that calls this alive; when it exits the state is no longer respected. Ultimately, though, you're fighting a losing fight -- per the docs, "the `SetThreadExecutionState` function cannot be used to prevent the user from putting the computer to sleep". It's a battle of hacks between those who think the machine should sleep and those who think it should not, with the poor OS stuck in the middle. – Jeroen Mostert May 22 '19 at 20:35
  • Interesting, so it seems I might have to turn to something trickier like a silent audio stream to have my way? I'm curious how PowerPoint is accomplishing this as I'd think it would use the same function that I'm using, yet it actually works in this environment. – Sean Weber May 22 '19 at 20:48

1 Answers1

0

Not a script: create a PowerPoint with a few slides; set up animation (time on each slide, etc - can Google); export as a video. Now here’s the new trick: in the past (at least at my company) I could set up the play mode to loop until Esc was pressed / but just got a refresh and the latest Win 10 stopped that from working. So now I first start Windows Media Player, select the ‘repeat’ icon, then drag my MP4 file in and drop it on the Play icon; reduce the size of the window and drag to the edge of the screen.

user3741598
  • 297
  • 1
  • 12