How can I prevent a policy-enforced screen lock in Windows?

If Windows Media Player is still installed, you can play a video on loop and minimize it (the sample "Wildlife" videos work fine for this). By default, as long as a video is playing, the screen won't lock.


I use a script I title idle.vbs:

Dim objResult

Set objShell = WScript.CreateObject("WScript.Shell")    

Do While True
  objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}")
  Wscript.Sleep (6000)
Loop

Every six seconds, this quickly toggles numlock on the keyboard, causing Windows to believe that someone is interacting with the keyboard, preventing screen lock. This runs on vanilla windows, you don't need development or scripting tools to use it, just make a text file with .vbs as the extension and double-click it (or place it in your startup items).

Edit: you can put this script in your startup items with

 choco install IdleVbs -source https://www.myget.org/F/joshrivers-utility/

For more information on the Choclatey (choco) CLI installer please see:

https://chocolatey.org/


Yet another option is freeware Caffeine program. It is free for commercial use as well. From the program's homepage:

If you have problems with your PC locking or going to sleep, caffeine will keep it awake. It works by simulating a key-press once every 59 seconds, so your machine thinks you're still working at the keyboard, so won't lock the screen or activate the screensaver.

Caffeine works by simulating an F15 key up event every 59 seconds. Of all the key presses available, F15 is probably the least intrusive (I've never seen a PC keyboard with that key!), and least likely to interfere with your work.

This off-the-shelf solution also allows you to control when to enable it and disable it:

Double-clicking the program icon empties the coffee pot, which is what the icon represents, and temporarily disables the program. Double-clicking it again refills the pot, and will keep your machine awake.