Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Our corporate BOFH imposes the screen lock setting with a ridiculously short delay. It's frustrating and counterproductive.

Is there a way to prevent the automatic screen lock? I would assume there is no way to override the policy-enforced setting, but maybe there is a software that mimics user activity.

Just asking before I set up a perpetual mouse wheel. (get it?)

share|improve this question
    
Just curious what "ridiculously short" is? –  Carl Aug 30 '11 at 15:45
    
There are workarounds like key pressers and mouse movers that will prevent the screen from locking. But are you sure you want to do this? Circumventing IT security is more than likely against company policy, and could be a fireable offense. –  Keltari Aug 30 '11 at 16:14
1  
15 minutes. OK, it's not that short ... unless you are at home, not in an open space, and also often working on a second computer. Like I am, so the screen lock is obnoxious. –  Gabriel R. Aug 31 '11 at 10:32
    
One semi workaround is not to block the screensaver, but to set the grace period to a few hours. (That is the time between the starting of the screensaver and the time you need to enter a password. Usually this is set to 5 seconds. So a quick shake with the mouse when the screensaver just kicks in disables it. However with a higher value you can have hours without a password. –  Hennes Dec 24 '13 at 20:14

5 Answers 5

up vote 20 down vote accepted

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.

share|improve this answer
    
Thank you! This is the simplest, most effective solution. (I didn't try it though, I left the company a while ago and try to stay away from Windows.) –  Gabriel R. Apr 16 '13 at 11:43
3  
I confirm that this works on Windows XP using an MP3 file instead of a video. –  Alaa Ali Sep 23 '13 at 9:59
1  
Brilliant hack! –  sirjorj Apr 2 at 13:51
    
This also works using VLC for those who prefer it over Windows Media Player –  ecoe May 5 at 15:22

Compile this in Visual Studio or C# Express and run it from a command prompt (or double click it). Requires .NET 4.0 or above. It does everything you are looking for.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms; 

namespace ImWorkin
{
    class Program
    {
        [FlagsAttribute]
        public enum EXECUTION_STATE : uint
        {
            ES_SYSTEM_REQUIRED = 0x00000001,
            ES_DISPLAY_REQUIRED = 0x00000002,
            ES_CONTINUOUS = 0x80000000
        }
        public SYSTEMTIMEOUTS TimeOuts
        {
            get { return sysTimeouts; }
        }
        public struct SYSTEMTIMEOUTS
        {
            public int BATTERYIDLETIMEOUT;
            public int EXTERNALIDLETIMEOUT;
            public int WAKEUPIDLETIMEOUT;
        }

        [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE flags);

        [DllImport("user32.dll", SetLastError = true, EntryPoint ="SystemParametersInfo")]
        internal static extern int SystemParametersInfo(int uiAction, int uiParam, ref int pvParam, int fWinIni);

        private static System.Threading.Timer preventSleepTimer = null;
        public const int SPI_GETBATTERYIDLETIMEOUT = 252;
        public const int SPI_GETEXTERNALIDLETIMEOUT = 254;
        public const int SPI_GETWAKEUPIDLETIMEOUT = 256;
        public static int Counter = 0;
        public static int timeOutinMS = 0;
        public static int batteryIdleTimer;
        public static int externalIdleTimer;
        public static int wakeupIdleTimer;
        public static SYSTEMTIMEOUTS sysTimeouts;


        static void Main(string[] args)
        {
            Console.WriteLine("You are about to be workin!! Just a moment...I need to calculate a few values.");
            string dots = string.Empty;
            for (int i =2; i < 60; i++)
            {
                dots = "";
                for (int ii = 0; ii < i; ii++)
                {
                    dots = dots + ".";
                }
                Thread.Sleep(100);
                Console.Clear();
                Console.WriteLine("You are about to be workin!! Just a moment...I need to calculate a few values.");
                Console.WriteLine(dots);
            }


            GetSystemTimeOuts();


            if (timeOutinMS < sysTimeouts.BATTERYIDLETIMEOUT)
                timeOutinMS = sysTimeouts.BATTERYIDLETIMEOUT;
            if (timeOutinMS < sysTimeouts.EXTERNALIDLETIMEOUT)
                timeOutinMS = sysTimeouts.EXTERNALIDLETIMEOUT;
            if (timeOutinMS < sysTimeouts.WAKEUPIDLETIMEOUT)
                timeOutinMS = sysTimeouts.WAKEUPIDLETIMEOUT;

            if (timeOutinMS == 0)
                timeOutinMS = 30;

            DisableDeviceSleep();
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("OK. I have calculated your computers timeout periods and set the   ");
            Console.WriteLine("necessary hooks. Your computer will not shut off the monitor, will");
            Console.WriteLine("show active in any chat programs,the screensaver is disabled and ");
            Console.WriteLine("the computer will not lock! Anyone looking at you eaither locally ");
            Console.WriteLine("or remotely will think you are hard at work.");
            Console.WriteLine("");
            Console.WriteLine("Now go do something fun...I got your back ;)");
            Console.WriteLine("Oh yeah....if you close this window OR press `q' in this ");
            Console.WriteLine("window you are going to have to actually work.");
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("This text will disappear in a 30 seconds. Just in case someone comes ");
            Console.WriteLine("by and reads your screen!");
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Need custom coding? Kenneth.gore@gmail.com");
            while (Console.KeyAvailable == false)
            {
                Thread.Sleep(250);
                ConsoleKeyInfo cki = Console.ReadKey(true);

                if (cki.KeyChar == 'q')
                    break;
            }

        }


        public static void DisableDeviceSleep()
        {
           SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
           preventSleepTimer = new System.Threading.Timer(new TimerCallback(PokeDeviceToKeepAwake), null, 0, timeOutinMS * 1000);
        }

        public static void EnableDeviceSleep()
        {

           preventSleepTimer.Dispose();
           preventSleepTimer = null;

        }

        private static void PokeDeviceToKeepAwake(object extra)
        {

            Counter++;
            try
            {
                   SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
                   IntPtr Handle = FindWindow("SysListView32", "FolderView");

                   if (Handle == IntPtr.Zero)
                   {
                       SetForegroundWindow(Handle);
                       SendKeys.SendWait("%1");
                   }

                   if (Counter > 1)
                       Console.Clear();
            } 
            catch 
            {

            }
        }

        public static void GetSystemTimeOuts()  
        {
            sysTimeouts.BATTERYIDLETIMEOUT = -2;
            sysTimeouts.EXTERNALIDLETIMEOUT = -2;
            sysTimeouts.WAKEUPIDLETIMEOUT = -2;


            if (SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT, 0, ref batteryIdleTimer, 0) == 1)
                sysTimeouts.BATTERYIDLETIMEOUT = batteryIdleTimer;
            else
                sysTimeouts.BATTERYIDLETIMEOUT = -1;

            if (SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT, 0, ref externalIdleTimer, 0) == 1)
                sysTimeouts.EXTERNALIDLETIMEOUT = externalIdleTimer;
            else
                sysTimeouts.EXTERNALIDLETIMEOUT = -1;



            if (SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT, 0, ref wakeupIdleTimer, 0) == 1)
                sysTimeouts.WAKEUPIDLETIMEOUT = wakeupIdleTimer;
            else
                sysTimeouts.WAKEUPIDLETIMEOUT = -1;


        }
    }
}
share|improve this answer
    
Sorry....in the above post everything after the phrase "Looking for." is code and should be compiled. It didn't format correctly. The code demonstrates some pretty cool pInvoke for those interested. Btw....after compiled, I just put it in my path somewhere like c:\windows. This way if I'm at a cmd prompt I can type ImWorkin and I'm good to go :) –  user205533 Mar 9 '13 at 3:34
    
You can modify your answer by clicking the edit link below it. –  Dennis Mar 9 '13 at 3:59
    
please edit your first answer and then delete this one. –  teylyn Mar 9 '13 at 4:00
1  
WTF is up with the "Just a moment, I'm calculating a few values!" dummy loop? –  KalEl Oct 24 '13 at 13:30

You can create an AutoIt script to either continually press an unused key (e.g. make it toggle the num lock, scroll lock), sleep for a minute or so, and repeat. Alternatively, if you use the keyboard a lot, you could make it move the mouse by a pixel or so in any direction.

If you don't want it continually running, you could also launch the script as a scheduled task (if you have access) to launch after the computer has been inactive for some time.

And this is a very simple script to perform an invisible mouse move, if you don't want to get into AutoIt syntax:

While True
   Local $pos = MouseGetPos()
   MouseMove($pos[0]-1, $pos[1]-1, 0)
   MouseMove($pos[0], $pos[1], 0)
   Sleep(540000)
WEnd

This script moves mouse cursor by one pixel in the up-left direction and after that returns it back, then sleeps for 9 minutes (540000 milliseconds). When script is running, you can see AutoIt icon in the tray. You can stop it right-clicking this icon and choosing the corresponding option.

To make a script, install AutoIt, right-click in any folder and choose New > AutoIt v3 Script, name it, right-click this new script, choose Edit, paste the code provided above and save. You can even compile it to .exe (again, from context menu) to start, for example, from Windows Scheduler.

share|improve this answer
    
Thanks, I'll check it out, seems simpler than a mouse wheel cage setup :) –  Gabriel R. Aug 31 '11 at 10:37

There is an android app called "Timeout Blocker" that vibrates at an interval and you can put your mouse on it. It says not to use it at work though. https://play.google.com/store/apps/details?id=com.isomerprogramming.application.timeoutblocker&hl=en

share|improve this answer

You should disable the "screen lock"/"sleep mode" from control panel > power options > change plan settings. Her in click the drop down for "Put the computer to sleep" and select "never".

share|improve this answer
1  
Domain admins can have a policy-enforced screen lock in Windows. –  Gabriel R. Nov 18 '13 at 17:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.