10

On my Windows 7 PC the system becomes locked after 10 minutes of inactivity. Usually I would find this setting next to the screen-saver configuration. The setting is grayed out, however.

I think this is because of corporate group policy. As I am an administrator on this computer I should be able to reconfigure the group policy setting using gpedit.msc.

What is the group policy setting that I need to change to prevent automatic locking of my workstation?

Edit: I don't have configured a screen-saver. I also want to continue to be able to lock the workstation manually.

usr
  • 2,440
  • 4
  • 23
  • 29

8 Answers8

13

To disable Lock:

Under HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft\Windows\CurrentVersion\Policies\System, create a new DWORD value named DisableLockWorkstation and set value to 1.

Then restart the computer.

Dave
  • 25,513
Jason
  • 146
5

The answer to the actual question you asked:

User Configuration\Policies\Administrative Templates\Control Panel\Personalization. The required settings are: 'Enable screen saver', 'Screen saver timeout', 'Force specific screen saver' (this is important because if the system has no screensaver configured this won't work) and finally 'Password protect the screensaver'.

from https://social.technet.microsoft.com/Forums/windowsserver/en-US/5c2518d4-f531-471a-a649-0f5dd5495679/group-policy-to-auto-lock-the-system-after-fix-interval?forum=winserverGP

CAD bloke
  • 873
3

The Group Policy from the domain will likely override any change you make. If this is creating an issue for your work, why not contact the admin and look at solutions. Making changes may be a violation of corporate policy and have consequences.

A quick call should help.

Dave M
  • 13,250
2

Group policy overrides your settings, but you can mimick user activity to prevent the screen lock. Check this answer for easy how to.

Neurotransmitter
  • 1,291
  • 16
  • 35
1

I wanted to do something similar.

I tried the freeware Caffeine but it was blocked by our IT policies. I ended up writing a Python script that does a similar thing (sending the keystroke F15 every xx seconds).

(It can definitely be trimmed to a minimum of lines but just got 15 minutes to spare on it so the first part is a big copy-paste of other code).

Here it is:

#!/python

import ctypes
import random
import re
import time
from argparse import ArgumentParser, HelpFormatter

LONG = ctypes.c_long
DWORD = ctypes.c_ulong
ULONG_PTR = ctypes.POINTER(DWORD)
WORD = ctypes.c_ushort


class MOUSEINPUT(ctypes.Structure):
    _fields_ = (
        ('dx', LONG), ('dy', LONG), ('mouseData', DWORD),
        ('dwFlags', DWORD), ('time', DWORD),
        ('dwExtraInfo', ULONG_PTR)
    )


class KEYBDINPUT(ctypes.Structure):
    _fields_ = (
        ('wVk', WORD), ('wScan', WORD),
        ('dwFlags', DWORD), ('time', DWORD),
        ('dwExtraInfo', ULONG_PTR)
    )


class _INPUTunion(ctypes.Union):
    _fields_ = (
        ('mi', MOUSEINPUT),
        ('ki', KEYBDINPUT)
    )


class INPUT(ctypes.Structure):
    _fields_ = (('type', DWORD), ('union', _INPUTunion))


def SendInput(*inputs):
    nInputs = len(inputs)
    LPINPUT = INPUT * nInputs
    pInputs = LPINPUT(*inputs)
    cbSize = ctypes.c_int(ctypes.sizeof(INPUT))
    return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)


INPUT_MOUSE = 0
INPUT_KEYBOARD = 1


def Input(structure):
    if isinstance(structure, MOUSEINPUT):
        return INPUT(INPUT_MOUSE, _INPUTunion(mi=structure))
    elif isinstance(structure, KEYBDINPUT):
        return INPUT(INPUT_KEYBOARD, _INPUTunion(ki=structure))
    else:
        raise TypeError('Cannot create INPUT structure (keyboard)!')


keys = {
    'DEFAULT': 0x7E,  # F15 key
    'SNAPSHOT': 0x2C,  # PRINT SCREEN key

    'F1': 0x70,  # F1 key
    'F2': 0x71,  # F2 key
    'F3': 0x72,  # F3 key
    'F4': 0x73,  # F4 key
    'F5': 0x74,  # F5 key
    'F6': 0x75,  # F6 key
    'F7': 0x76,  # F7 key
    'F8': 0x77,  # F8 key
    'F9': 0x78,  # F9 key
    'F10': 0x79,  # F10 key
    'F11': 0x7A,  # F11 key
    'F12': 0x7B,  # F12 key
    'F13': 0x7C,  # F13 key
    'F14': 0x7D,  # F14 key
    'F15': 0x7E,  # F15 key
    'F16': 0x7F,  # F16 key
    'F17': 0x80,  # F17 key
    'F18': 0x81,  # F18 key
    'F19': 0x82,  # F19 key
    'F20': 0x83,  # F20 key
    'F21': 0x84,  # F21 key
    'F22': 0x85,  # F22 key
    'F23': 0x86,  # F23 key
    'F24': 0x87,  # F24 key
}

def Keyboard(code, flags=0):
    # Code for key 0..9 or A..Z: it corresponds to the the ASCII code
    if len(code) == 1 and re.match(r'[0-9A-Za-z]', code):
        key = ord(code.upper())
    # Keys 'F...': we use code in the dictionary
    else:
        key = keys.get(code.upper(), keys['DEFAULT'])
    return Input(KEYBDINPUT(key, key, flags, 0, None))


############################################################################

sentences = [
    "Don't sleep!",
    "Stay awake!",
    "Are you still here?",
    "Hello...",
    "Want some coffee?",
    "What are you doing?"
]


def keep_alive(delay, nb_cycles=-1, key='F15'):
    """
    Send keystroke F15 at a given delay for a given nb of cycles

    Args:
        delay(int): delay in seconds
        nb_cycles(int): number of cycles (set to -1 for unlimited)
        key(str): Key to send (default: 'F15')
    """
    print("Trust me, I will keep you alive!\n")   
    while nb_cycles != 0:
        time.sleep(delay)
        SendInput(Keyboard(key))
        print(random.choice(sentences))
        nb_cycles -= 1


if __name__ == '__main__':
    # Information on the Program
    copyright_year = 2018
    prog = "stay_awake"
    version_str = "%s v1.0" % prog
    help_string = """\
    Purpose: Send a keystroke (F15) to simulate user activity
    """

    # Options
    parser = ArgumentParser(
        description=help_string, prog=prog,
        formatter_class=lambda prog:
        HelpFormatter(prog, max_help_position=60)
    )
    parser.add_argument(
        "-k", "--key",
        type=str, default='F15',
        help="Key to send [Dflt: F15]"
    )
    parser.add_argument(
        "-d", "--delay",
        type=int, default=234,
        help="Delay (in s) between keystrokes [Dflt: 234]"
    )
    parser.add_argument(
        "-r", "--duration", 
        type=int, default=-1,
        help="Duration (in s) or negative value for infinite"
    )
    options = parser.parse_args()

    # Run
    nb_cycles = options.duration if options.duration < 0 \
           else int(options.duration/options.delay)
    keep_alive(options.delay, nb_cycles, key=options.key)
1

Like others have said, the domain policy will generally override any local settings you try to configure for this. There's a couple other things I'd like to add, though:

Be careful tweaking this setting, whether it be via registry or otherwise. I once tried messing with mine on one system (domain policy is to lock after 15 minutes, but I prefer 5 - can't remember what I changed, though) and the system ended up listening to neither the domain nor my preference even after I rolled back the change. In this case, it ended up not running a screensaver at all. That's exactly what you want, but definitely not what I'd intended. YMMV.

Regardless: Unless your system is the sort that requires full-time immediate access, for the preservation of life and/or property (i.e.: 911 Call Center), it is probably against your organization's policy to prevent the workstation from locking. If your system did fall into that category, then it would probably already be configured not to lock. Therefore, it's best to just leave it alone.

Even if you do manage to change the setting permanently, corporate administrators may detect the computer as being out of compliance and force the policy on again. After a few times of doing this, you or your manager may get a memo or visit from your friendly IT Security department.

Iszi
  • 14,163
1

Just play some songs in Windows media player by selecting in repeat option.(Mute the volume). Then it never locks or sleeps.

1

You can use the Nosleep.exe function. It works like a charm. You need to download it from the internet.

This works on Windows 8/7/2008R2/2003 R2

Download link http://www.symantec.com/connect/downloads/readynosleepexe-prevents-screensaver-and-pc-locking

Gontie
  • 11