178

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?)

Gabriel R.
  • 1,968
  • 2
  • 12
  • 12
  • 5
    Just curious what "ridiculously short" is? – Carl Aug 30 '11 at 15:45
  • 1
    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
  • 11
    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
  • 1
    [The grace period](https://superuser.com/questions/329758/how-can-i-prevent-a-policy-enforced-screen-lock-in-windows-7/836346#comment880491_329758) doesn't work for me, while [the script](https://superuser.com/a/836346/137079) does. I assume that my corporate policy also disables the grace period. – Dane Jacob Hampton Apr 20 '18 at 08:41
  • 1
    Late to the game here, but wanted to add my solution. Since I don't have admin rights to the PC I use at work, and none of the scripts or programs in this thread worked for me (either they weren't allowed to be installed, or just didn't work), I purchased a "USB Mouse Jiggle" hardware from Amazon. Works like a dream, only $15. – Jeff Wright Apr 30 '18 at 11:01
  • 5
    My previous company has a 2-minute screen lock policy. That's not ridiculous but disaster and torturous and sometimes depressing. – Lame User Dec 27 '19 at 08:07
  • In the end, I had to use a macro-enabled excel workbook and use macro to move the mouse because everything else was blocked, as given by this video https://www.youtube.com/watch?v=yHGI0d0ImNo – EDM Jul 14 '20 at 06:27
  • Try mouseJiggle: https://mouse-jiggler.en.uptodown.com/windows – user2469134 Aug 05 '20 at 12:07
  • 2
    This is an excellent way to get fired. – Keltari Jun 24 '21 at 02:21
  • +1 Just for using the term BOFH `:D` – mpy May 16 '23 at 18:37

18 Answers18

135

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.

omaha_brad
  • 1,467
  • 2
  • 9
  • 3
  • 8
    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
  • 6
    I confirm that this works on Windows XP using an MP3 file instead of a video. – Alaa Ali Sep 23 '13 at 09:59
  • 6
    Brilliant hack! –  Apr 02 '14 at 13:51
  • 7
    This also works using VLC for those who prefer it over Windows Media Player – ecoe May 05 '14 at 15:22
  • 3
    Great hack. I built a small blank video and batch scripts to start this. Files at [box.net](https://app.box.com/s/khcc45viol53oswmzo3v) and a blog post at [my personal site](http://www.ericcloninger.com/?p=578) – Eric Cloninger Nov 26 '14 at 19:44
  • 1
    @EricCloninger this doesn't play on W2k3 SP2 Media Player; good idea though – kubanczyk Jan 17 '15 at 13:22
  • 1
    @kubanczyk I had some problems with WMP on Windows 7 to launch into looping mode from a script, but I could launch the video and then manually choose the looping button on the control bar. – Eric Cloninger Jan 17 '15 at 21:45
  • 4
    Works fine in Windows 7. Nice hack! – neves Nov 05 '16 at 01:52
  • 1
    If you're using VLC, this will only work if the video window is not minimized (but it can be in the background). – Joe Mornin Mar 01 '18 at 17:21
  • This works on Windows 7 playing an MP3 in minimized Media Player instead of video. – Chris Jenks May 23 '18 at 16:09
  • 1
    Does it works on win 10 ? – Shatayu Darbhe Jun 28 '19 at 03:44
  • 1
    @ShatayuDarbhe yes, it works with Windows 10 as well. – Filip Nikolov Jul 29 '20 at 09:10
  • For those who don't have "Wildlife" or any videos on your computer, you could probably find some free-to-use ones from [Wikimedia Commons](https://commons.wikimedia.org/wiki/Commons:Featured_videos/en), most companies I know will allow you to access Wikipedia and thereby Commons. But unfortunately, this method does not work for me. – zypA13510 Mar 01 '21 at 05:44
  • Any ideas to make this as light on system resources as possible? (e.g. which file, from Wikimedia Commons or Windows system sounds or other, would be "best" suited) – nutty about natty Apr 15 '21 at 14:41
  • 1
    Playing some small *.midi file in Windows Media Player uses some ~ 35MB RAM (in Win10) vs. < 1MB for Caffeine... – nutty about natty Apr 20 '21 at 11:41
  • This should be the accepted answer because it works without the need to install any additional applications. The Caffeine answer seems like it works, but some companies track the apps you install on your computer. And apps that occasionally perform keystrokes could potentially have unintended consequences. – InvalidBrainException Oct 13 '21 at 10:10
  • Would playing songs on spotify have the same effect? – Vasiliki Oct 18 '21 at 12:54
126

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/

Hack-R
  • 379
  • 3
  • 5
  • 20
JoshRivers
  • 1,377
  • 1
  • 9
  • 7
  • 1
    @JoshRivers a way to stop this script, without having to restart the computer, would be nice as well. – DeeJayh Feb 03 '17 at 17:52
  • 8
    @DeeJayh I think you can just find the instance of wscript.exe in Task Manager and kill it. There usually aren't a lot of instances of that executable running. You could probably make an automated solution for termination (http://stackoverflow.com/a/22325745) or by putting code in the Do While section that watches for an external fact. Like have the script create a file on startup, then check that the file exists in While. That way you could just delete the file to make the script terminate. (I never quit the thing, though, so I just run the script and very rarely kill it with Task Manager). – JoshRivers Feb 04 '17 at 20:28
  • 3
    On Windows 10, an easy way to locate the startup folder is display the Start->Run window (e.g. WindowsKey+R) and then type `shell:startup`. See this site for more info http://www.thewindowsclub.com/startup-folder-in-windows-8 – buzz3791 Apr 12 '18 at 15:55
  • 1
    To find the script look for Microsoft Windows Based Script Host in your task manager. Or add a column Process Name and then look for wscript.exe. – WJA Jun 06 '18 at 08:30
  • 1
    Works great on a Win10 Surface laptop - that does not even have a physical NumLock key! – Shahar Dec 19 '18 at 15:45
  • This seems to work great UNLESS Outlook (365) is the active window and then it doesn't seem to prevent screen lock. Has anyone else noticed this? – raeldor Feb 21 '20 at 22:54
  • Not working for me – Germán Bouzas Oct 16 '20 at 14:10
  • confirming that this doesn't work for me either - probably the policy at hand in my case checks for mouse pointer movement.. i wish we could do this too using VBS but it seems to not be possible https://stackoverflow.com/questions/33019106/how-to-move-the-mouse-using-vbscript – hello_earth Mar 26 '21 at 11:31
45

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.

Ilya Kurnosov
  • 631
  • 7
  • 5
  • 27
    I'm waiting for the day when a Gov't employee puts Caffeine on their computer and it just so happens that something like Shift+F15 launches the nukes... – kazoni Jun 24 '15 at 17:37
  • Nice easy "off the shelf" solution, thanks. Seems to have about as many command-line options as gcc, but I don't need to use any of them! – Sam Watkins Aug 04 '16 at 03:07
  • 1
    The tool works great for me! I had to install the Visual C++ 2008 Redistributable to get it working. https://www.microsoft.com/en-us/download/details.aspx?id=26368 – Synck Oct 02 '19 at 07:07
  • 2
    I think in a corporate environment you could (and should) get into trouble for installing such a tool on a machine, especially if it's not 'your' machine. The VBS solution is much cleaner, at least you know exactly WHAT it does. – Bartosz Jul 23 '20 at 09:14
  • 2
    Please keep in mind that simulating key presses is a quite brutal way to keep your screen from locking. For a better way, please check my [answer](https://superuser.com/a/1604470/1182474) out. – PolarBear Nov 23 '20 at 19:20
  • @PolarBear What about Caffeine with the -stes - tell Windows to stay awake, don't use F15 – Cfomodz Sep 01 '21 at 19:24
  • 1
    @Cfomodz, indeed, I see that they have added the `-stes` option recently (v1.95 - February 2021). I haven't tested it. My previous comment was written before this option was introduced. If the option does what it promises then it is the same as the `CoffeeBean` program which I recommended in my previous comment. – PolarBear Sep 02 '21 at 07:04
  • @PolarBear Fair enough. I suppose I didn't even think about that, but I'm glad I didn't make a fool of myself by trying to say you should have suggested it before it existed haha. It does indeed - or at least it has for me - do what it says it does and seems to be the same as 'CoffeeBean' based on your description. – Cfomodz Oct 17 '21 at 05:28
  • Microsoft has recently released their version of a similar tool [PowerToys Awake](https://learn.microsoft.com/en-us/windows/powertoys/awake) – PolarBear Feb 18 '23 at 18:40
13

A lot of these answers are old, and only keep alive through inputs/mouse movement. Compile this in C or C++, this will keep the session alive by setting thread execution state (Windows Only ofcourse)

#include <windows.h>

//https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate

#define ES_CONTINUOUS       0x80000000
#define ES_DISPLAY_REQUIRED 0x00000002
#define ES_SYSTEM_REQUIRED  0x00000001

int main()
{
    int result = 0;
    while(1)
    {
        result = SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
        Sleep(30 * 1000);
    }

    //unreachable
    return 0;

}
Cherona
  • 413
  • 1
  • 5
  • 14
10

1. (Best option) Microsoft PowerToys Awake

PowerToys Awake enter image description here

How it works under the hood

The tool uses the SetThreadExecutionState WinApi function to keep the screen on. It is the function that video players use to keep the screen on while you are watching a film.

2. CoffeeBean

I have created a tiny tray icon application CoffeeBean which is very similar to the PowerToys Awake. The only advantage of my tool is that it can be used as a standalone executable without installation.

3. Autohotkey script

If you are familiar with the Autohotkey tool, you can use the following script.

PolarBear
  • 363
  • 3
  • 8
  • The key thing here is SetThreadExecutionState - thank you! It's then a moments work to create an app/script/whatever and use Task Scheduler to run it every 10 minutes. – Rhys Jones May 28 '21 at 18:25
  • 1
    @RhysJones, I'm not sure running it once per 10 minutes is going to work well. You don't need to run it periodically. You just need to run it once and keep the process alive. As long as the thread which called `SetThreadExecutionState` function is alive, OS is not going to lock the screen. That is the idea behind my tray icon application and the Autohotkey script. – PolarBear Jun 01 '21 at 06:50
  • You are right - as Hexagon has also noted, the docs are not very precise. – Rhys Jones Jun 02 '21 at 05:56
8

I like to use easy and integrated options (no additional software), like a powershell script (thanks https://dmitrysotnikov.wordpress.com/2009/06/29/prevent-desktop-lock-or-screensaver-with-powershell/) that uses the "f15" as the key to success (thx to caffeine. It's indeed least interfering)

param($minutes = 180)

write "... screen will be awake for $minutes"

 $myshell = New-Object -com "Wscript.Shell"

 for ($i = 0; $i -lt $minutes; $i++) {
 write "... screen will be awake for" ($minutes-$i)
 Start-Sleep -Seconds 60    
 $myshell.sendkeys("{F15}")
}

Put this into a myScriptName.ps1 and start it via desktop shortcut or commandline: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nop "C:\Users\myUser\Desktop\myScriptName.ps1"

UPDATE: Maybe there was some change from the administrator, but this doesn't work for me anymore Now I have to use an autohotkey-script from NBirnel: https://github.com/nbirnel/nosleep - this work perfect, because it moves the mouse (without distracting any work)

MacMartin
  • 883
  • 9
  • 12
  • I run the code but getting the following error. Please advise `c:\Powershell>powershell -nop myScriptName.ps1 myScriptName.ps1 : The term 'myScriptName.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + myScriptName.ps1 + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (myScriptName.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException c:\Powershell>` – Sabrina Nov 15 '18 at 13:24
  • 1
    @Sabrina maybe you have to define the full path to your script, so not just "myScriptName.ps1" but "c:\path\to\myScriptName.ps1" – MacMartin Nov 19 '18 at 13:37
  • Can be done as an one-liner shortcut: `powershell.exe -Command $s = New-Object -com \"Wscript.Shell\"; while(1){write \".\"; $s.sendkeys(\"{F15}\"); Start-Sleep -Seconds 60;}` This helps against the policy forbidding PowerShell to execute files. Can be started "minimised" at once. – Alexander Sep 20 '21 at 11:50
8

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.

David Marshall
  • 7,200
  • 4
  • 28
  • 32
Breakthrough
  • 34,227
  • 10
  • 105
  • 149
  • Thanks, I'll check it out, seems simpler than a mouse wheel cage setup :) – Gabriel R. Aug 31 '11 at 10:37
  • Precompiled version of this AutoIt Script here https://www.symantec.com/connect/downloads/readynosleepexe-prevents-screensaver-and-pc-locking – JJS Nov 29 '16 at 21:10
7

Extending on Cherona's answer, here is an implementation in PowerShell, using SetThreadExecutionState().

As long the script is running, screen saver and screen lock wouldn't start.

Set-StrictMode -version 3.0

# Definition of SetThreadExecutionState from -
#   http://www.pinvoke.net/default.aspx/kernel32/SetThreadExecutionState.html
#   https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
# "EXECUTION_STATE" changed to "uint", added "public" modifier.
$Signature = @'
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern uint SetThreadExecutionState(uint esFlags);
'@

$ES_AWAYMODE_REQUIRED = 0x00000040L
$ES_CONTINUOUS        = 0x80000000L
$ES_DISPLAY_REQUIRED  = 0x00000002L
$ES_SYSTEM_REQUIRED   = 0x00000001L

# Details on Add-Type in https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/add-type?view=powershell-7.
$Kernel32 = Add-Type -MemberDefinition $Signature -Name 'Kernel32' -Namespace 'Kernel32' -PassThru

echo "Forcing system to not go to sleep (disable screen saver)."
echo "Close the window to allow sleep again."
$result = $Kernel32::SetThreadExecutionState($ES_CONTINUOUS -bor $ES_DISPLAY_REQUIRED -bor $ES_SYSTEM_REQUIRED)

# Loop until script is forcibly stopped.
While ($true) {
  Start-Sleep (60 * 60 * 24)  # 24 hours.
}
Hexagon
  • 273
  • 3
  • 8
  • Have you tested this? I was under the impression that you need to keep calling SetThreadExecutionState every so often, to reset the "system idle timer" described here https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate – Cherona Oct 24 '20 at 08:10
  • 1
    @Cherona Yes, I verified that this works for many hours (with the lock screen timeout being set to 1 minute). The documentation is indeed vague, but ES_CONTINUOUS could be interpreted as taking care of that. – Hexagon Oct 24 '20 at 09:37
6

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

Matt
  • 69
  • 1
  • 1
5

Mouse Jiggler might be an option: https://mousejiggler.codeplex.com/

KERR
  • 557
  • 6
  • 8
5

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;


        }
    }
}
Dennis
  • 48,917
  • 12
  • 130
  • 149
user205533
  • 51
  • 1
  • 2
  • 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 09 '13 at 03:34
  • 1
    You can modify your answer by clicking the **edit** link below it. – Dennis Mar 09 '13 at 03:59
  • please edit your first answer and then delete this one. – teylyn Mar 09 '13 at 04:00
  • 10
    WTF is up with the "Just a moment, I'm calculating a few values!" dummy loop? – KalEl Oct 24 '13 at 13:30
  • 10
    In response to the c# code posted its usually customary to give credit to the author. That happens to be me. I posted this almost two yeas ago on stack Overflow I believe. –  Jan 11 '15 at 16:59
  • It seems that `SPI_GETBATTERYIDLETIMEOUT`, `SPI_GETEXTERNALIDLETIMEOUT` and `SPI_GETWAKEUPIDLETIMEOUT` are only [documented](https://docs.microsoft.com/en-us/previous-versions/ms942638(v=msdn.10)) as working with Windows CE. – Marc Durdin Oct 13 '20 at 05:19
4

This is a solution which works for Win10 and with MS Office (that is, PowerPoint) installed:

MS PowerPoint (if MS Office is installed). Hit F5 to start "presentation mode". Now move to a different "desktop" (so that the "presentation" doesn't interfere with your actual work) by pressing Windows-logo + Tab, and you're good to go :)


PS: it might also work for Win7 without multiple "desktops", e.g. with Alt + Tab.

2

I've been using Mouse Move this for ages now. Advantage over Caffeine, options are customisable via GUI.

The Windows 10 version seems new, needs to be installed from Windows Store. Recommend the older one since is portable.

enter image description here

tinker
  • 260
  • 2
  • 12
1

I love @JoshRivers 's solution of VB script. And I updated a little bit to stop it with duration time.

Dim objResult
Dim intervalSec
Dim durationSec
Dim cnt

intervalSec = 60
durationSec = 3600

cnt = 0

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

Do While True
  objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}")
  Wscript.Sleep (intervalSec*1000)
  cnt = cnt + 1
  If durationSec <= (intervalSec * cnt) Then
      Exit Do
  End If
Loop
Youngmin Kim
  • 171
  • 1
  • 3
1

In my case just this one line did the trick:

SendKeys.Send("{CAPSLOCK}{CAPSLOCK}");

Just put it in the Timer_Tick event and set timer interval to e.g. 60000ms.

Engineer Toast
  • 4,955
  • 1
  • 20
  • 33
user3540753
  • 111
  • 3
  • 6
    ok, it's quite late to resume this answer but consider sending not one but two CAPSLOCK if you don't want me to staRT YELLING IN THE MIDDLE OF A STACKOVerflow comment without understanding why (it tooks a couple of minutes to write this comment) – Gian Paolo Sep 03 '18 at 08:31
  • @GianPaolo you're right. This is what I did. I thought it's clear but maybe I should modify the answer. – user3540753 Sep 11 '18 at 07:36
  • And 6 years after answering it’s still a single capslock invoke... smh – enorl76 Jun 10 '20 at 17:01
  • Great if this answer could be put into context... e.g. save it as a script, execute in cmd, ... ? - on second thought, other answers provide the context, e.g. https://superuser.com/a/836346/183485 – nutty about natty Jan 04 '21 at 11:14
0

Everyone else are writing scripts to fake being at the keyboard.

The correct way to handle it is to:

  • go into the registry where the policy is
  • set the value to whatever you want
  • and alter the registry key permissions
  • only Deny write access to anyone except yourself

This lets you block the policy from taking effect on your PC. But be aware that you need to have Administrator access to the registry.

Ian Boyd
  • 21,642
  • 49
  • 139
  • 184
  • 3
    When the admins disable the screen lock settings, editing the registry is already disabled. – Gabriel R. Oct 04 '18 at 15:35
  • @GabrielR. As an administrator you can alter the ACL on the registry keys. If i get the patience i'll link the talk from Mark Russinovish where he mentions getting rid of the Microsoft group policy that locked down his own laptop. If you're an administrator you have full control of the machine. It likely has to start with taking ownership of the registry keys, then granting yourself full control, then denying anyone else anything except read access. – Ian Boyd Oct 04 '18 at 16:43
  • I have administrative access and can regedit. How can I find where the policy is set in the registry? I also couldn't find it in gpedit in the usual places. – Blaisem Sep 14 '22 at 16:44
  • @IanBoyd I actually am getting a special logon via lsass.exe from the system user in my event logs under security just before I'm timed out. Is this really a group policy / registry thing? – Blaisem Sep 14 '22 at 17:26
0

Mouse Jiggler was the right option for me*

the mouse does not actually move using the zen switch.

a working download link (2022/01): https://mouse-jiggler.fr.uptodown.com/windows

one file, 984Ko, no registry key.

Unzip, run. Use the swithes below from a console or a shortcut to autorun :

MouseJiggler.exe -j -m -z -s 50

this will start MouseJiggler activated (j), minimized (m), with no visible moves (j), triggered every 50 secs.

sources, MouseJiggler switches, chocolatey installation : https://github.com/arkane-systems/mousejiggler

(*) thanks @kkr for your answer. Cafeine was not working for me using the -stes arg (I use putty a lot)

jerome
  • 31
  • 2
-5

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".