I had a simlar problem, except it was that the screen saver would come on, but the time settings I had setup were not working, i.e. This causes the screensaver to only run for 30 seconds every 10 minutes. # Sleep for some time before checking againĮDIT: The only thing I need to improve in this script is that it will continue to lock the screen every 30 seconds after it is already locked. $LockWorkStation::LockWorkStation() | Out-Null If (::IdleTime.TotalSeconds -gt $IdleTime) Public static extern bool = Add-Type -memberDefinition $signature -name 'Win32LockWorkStation' -namespace Win32Functions -passthru Return Define DLL connection to lock screen Lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO)) Private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii) ĭateTime bootTime = (-Environment.TickCount) ĭateTime lastInput = bootTime.AddMilliseconds(LastInputTicks)