Created
June 4, 2026 07:42
-
-
Save mikeplate/fc4bb589dddcac9a3ce09b163ef141c8 to your computer and use it in GitHub Desktop.
Awake - PowerShell script to keep computer running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Add-Type @" | |
| using System; | |
| using System.Runtime.InteropServices; | |
| public static class Power { | |
| public const uint ES_CONTINUOUS = 0x80000000; | |
| public const uint ES_SYSTEM_REQUIRED = 0x00000001; | |
| [DllImport("kernel32.dll", SetLastError=true)] | |
| public static extern uint SetThreadExecutionState(uint f); | |
| } | |
| "@ | |
| if ([Power]::SetThreadExecutionState( | |
| [Power]::ES_CONTINUOUS -bor [Power]::ES_SYSTEM_REQUIRED | |
| ) -eq 0) { | |
| throw "Failed: $([Runtime.InteropServices.Marshal]::GetLastWin32Error())" | |
| } | |
| Read-Host "Press Enter to allow sleep again" | |
| [Power]::SetThreadExecutionState([Power]::ES_CONTINUOUS) | Out-Null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment