How to stop your screen going blank and logging you out

Infrequently used laptop screen going to sleep and logging you out? I have the fix for you? Maybe you need to appear logged on Teams when you're not using your computer (for legitimate reasons of course!) I have you covered!
August 26 2021

I was recently given a corporate laptop to work on. It sucks. Its slow as balls, making it infuriating to work with.  Not to mention it's a corporate laptop so comes with all their monitoring.  I switched over to my regular work laptop, which is blazing fast and has my regular development environment on it (YAY!).

The problem is my corporate laptop, which has Microsoft Teams and access to other resources, like JIRA, on it, keeps going to sleep.  As a result I have to regularly log back in so I can check Teams, or even look at the content in Jira.  So painful!  Oh, and I also appear to be away on Teams.  Not good, and not accurate - as it's sitting right there beside me, to my right.

The main problem was that due to corporate group policy I coudn't change the screen timeout.  Modern problems require modern solutions they say.  Back in the day I'd have written some AutoHotKey or something.  But now: POWERSHELL!

clear host
# Script to keep the PC alive, will prevent screen lock and sleep.
# Works by pressing Print Screen every 5 minutes. Side effect is that a screenshot it dropped is your clipboard.
$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 {
    Start-Sleep -Seconds 300
} While ($true) 

Post a comment

comments powered by Disqus