Created
March 7, 2021 09:33
-
-
Save woffleloffle/5dea012d2f238dbd94cedca9b373ec10 to your computer and use it in GitHub Desktop.
Script to keep a PC alive, will prevent screen lock and sleep.
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
clear host | |
# | |
# Script to keep the PC alive, will prevent screen lock and sleep. | |
# | |
# Works by pressing Print Screen every 60 seconds | |
# side effect is that a screenshot will overwrite the clipboard contents | |
# | |
$opt = (Get-Host).PrivateData | |
$opt.WarningBackgroundColor = "DarkCyan" | |
$opt.WarningForegroundColor = "white" | |
write-warning "Your PC will not go to sleep whilst this window is open..." | |
Do { | |
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | |
[System.Windows.Forms.SendKeys]::SendWait("{PRTSC}") | |
Start-Sleep -Seconds 60 | |
} While ($true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment