Skip to content

Instantly share code, notes, and snippets.

@woffleloffle
Created March 7, 2021 09:33
Show Gist options
  • Save woffleloffle/5dea012d2f238dbd94cedca9b373ec10 to your computer and use it in GitHub Desktop.
Save woffleloffle/5dea012d2f238dbd94cedca9b373ec10 to your computer and use it in GitHub Desktop.
Script to keep a PC alive, will prevent screen lock and sleep.
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