Skip to content

Instantly share code, notes, and snippets.

@AndrewPardoe
Last active May 10, 2020 00:57
Show Gist options
  • Save AndrewPardoe/944957cc9da0f0d9604b117e7963037d to your computer and use it in GitHub Desktop.
Save AndrewPardoe/944957cc9da0f0d9604b117e7963037d to your computer and use it in GitHub Desktop.
Temporarily prevent Windows machine from sleeping, allows monitors to turn off
#pragma comment(lib, "Kernel32")
#include <conio.h>
#include <Windows.h>
#include <WinBase.h>
int main()
{
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
_cputs("System state set to not sleep.\nPress `t` to revert state and terminate.\n");
char c;
do {
c = toupper(_getch());
}
while (c != 'T');
SetThreadExecutionState(ES_CONTINUOUS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment