Windows: Prevent Lock Screen Timeout When Idle

Corporate Windows computers and servers are usually configured to lock the screen after some time of inactivity.

This is especially inconvenient when your remote desktop session keeps disconnecting with “RDP Session Timeout” each time after few minutes of being idle.

In this article i will show how to stop computer from locking and keep the remote desktop session alive without any 3rd party tools and admin privileges, but with just 2 lines in PowerShell.

Cool Tip: Clear history of previous commands in PowerShell! Read more →

Prevent Lock Screen Timeout in Windows

To prevent Windows from locking when idle, to prevent termination of RDP session after timeout and to keep Skype for Business or any other messenger from going inactive, you can simulate key pressing with PowerShell.

Simply open the PowerShell and execute the following two lines of code:

$WShell = New-Object -Com Wscript.Shell
while (1) {$WShell.SendKeys("{SCROLLLOCK}"); sleep 60}

The first line creates a Windows scripting -Com Wscript.Shell object, while the second line creates an infinite loop during which it presses the SCROLLLOCK key (which seems to be useless nowadays) each minute.

These lines can be saved as a file with .ps1 extension, e.g. Disable-Screen-Lock.ps1, that can be executed with the right click and “Run with PowerShell“.

This PowerShell script will prevent the “RPD Session Timeout“, will stop your computer from locking, will disable screensaver and will make your Skype status always online.

Cool Tip: Kill a hanging process in Windows from the CMD! Read more →