Forum Discussion

ColtenHood's avatar
ColtenHood
Copper Contributor
Oct 13, 2024

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 

No RepliesBe the first to reply

Resources