Keeping your managed PC from locking all the time

I know you shouldn’t try and subvert your companies internal security policies, but sometimes the security department just don’t seem to understand the consequences of what they do…especially when using multiple computers simultaneously!

The following script essentially presses the inaccessible F15 key at regular time intervals to ensure the screen timeout is reset and you avoid locking out.

Save the following script as KeepUnlocked.ps1 and then you can execute this with the defaults (keep unlocked for 2 hours) or override the parameters like

.\keepunlocked.ps1 -KeepUnlockedMinutes 360 -KeyPressEveryMinutes 4

which will keep it unlocked for 6 hours tapping the F15 key every 4 mins.

If you get a permissions warning, then execute line 2 first.

# Permissions: Need execution rights on the laptop, then run the following line
# Set-ExecutionPolicy -executionpolicy unrestricted -scope CurrentUser

#Usage: .\keepunlocked.ps1 -KeepUnlockedMinutes 360 -KeyPressEveryMinutes 4

	$KeepUnlockedMinutes = 120,
	$KeyPressEveryMinutes = 4

write-host "Keeping unlocked for $KeepUnlockedMinutes not close this window"
write-host "Press CTRL+C to quit"
$myshell = New-Object -com "Wscript.Shell"
for ($i = 0; $i -lt $KeepUnlockedMinutes; $i+=$KeyPressEveryMinutes) {
 Start-Sleep -Seconds ($KeyPressEveryMinutes * 60)

Credit for this script must go to my colleague Sergejs Cesalins…thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.