Forum Discussion
ColtenHood
Oct 13, 2024Copper Contributor
Prevent Your Computer from Automatically Locking
Here is an alternate method to prevent your computer from locking.
Code:
function KeepScreenAwake {
param($minutes = 9999)
Write-Host "The screen will remain active for $minutes minutes."
$wshell = New-Object -ComObject Wscript.Shell
for ($i = 0; $i -lt $minutes; $i++) {
Write-Host "The screen will be active for another $($minutes - $i) minutes."
Start-Sleep -Seconds 60
$wshell.SendKeys("{NUMLOCK}{NUMLOCK}")
}
}
KeepScreenAwake
1 Reply
- JustinKingIron Contributor
Adjust $minutes parameter as needed (default is 9999 minutes, roughly 7 days). Be cautious with scripts that send keystrokes, especially if you're working on something sensitive.