Last active
February 7, 2025 16:03
-
-
Save crpietschmann/eed4467834998ff161c6bea58c675342 to your computer and use it in GitHub Desktop.
PowerShell Script to Keep PC Awake
This file contains 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
## KeepAwake.ps1 | |
## Use SendKeys to toggle the Scroll Lock key | |
## | |
## This will keep the PC awake and prevent | |
## it from going to sleep. | |
## | |
## Author: Chris Pietschmann (https://build5nines.com) | |
$timerseconds = 60 * 4 ## Every 4 minutes | |
$myshell = New-Object -com "Wscript.Shell" | |
while ($True -eq $True) { | |
$myshell.sendkeys("{SCROLLLOCK 2}") | |
Write-Output "Keeping Awake... $(Get-Date)" | |
Start-Sleep -Seconds $timerseconds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simpler in a profile function, sleeps for 4 mins and scrollLock on/off
cat function:myAlive
$WShell = New-Object -com "Wscript.Shell"
while ($true) {
$WShell.sendkeys("{SCROLLLOCK}")
Start-Sleep -Milliseconds 100
$WShell.sendkeys("{SCROLLLOCK}")
Start-Sleep -Seconds 240
}