Force lock windows after set time

Page 1 of 2 12 LastLast

  1. Posts : 13
    7 64 ultimate
       #1

    Force lock windows after set time


    Hi,

    I looking for a way to limit time on the PC - auto lock Windows after 30 minutes, even (and especially) when the computer is not idle.
    When the user will log back into Windows by entering the Windows password, the counter will start again from 30 minutes.

    The app should start automatically and silent with Windows, and the user should not be able to stop this app without a password.

    Thanks, Nir.
      My Computer


  2. Posts : 12
    win10 64 bit
       #2

    Use parental controls. Only works on user accts, not admins.
      My Computer


  3. Posts : 13
    7 64 ultimate
    Thread Starter
       #3

    Thanks, but user accounts, from what I saw, can only limit certain hours of the day, and not number of minutes since login. I want the system to lock 30 minutes after login.
      My Computer


  4. Posts : 428
    Windows Seven x64
       #4

    Hey Nir,
    I don't know a program that offers what you are asking but maybe I can throw some ideas at you to try out.

    I know Windows 7 has Parental Controls that offer time limits which may be similar to what you are asking for. You also might be able to configure a batch script that starts every time a user logs into the computer. This would be configured with task scheduler and in the batch script the command to lock the computer would be:

    Code:
    %windir%\System32\rundll32.exe user32.dll, LockWorkStation
    To make a countdown in batch you could use the timeout /t command in CMD which counts down before the next command is executed.
    In the end the batch script would look something like this,
    Code:
    timeout /t 1800
    %windir%\System32\rundll32.exe user32.dll, LockWorkStation
    Hope this Helps,
    Ryan
      My Computer


  5. Posts : 17,545
    Windows 10 Pro x64 EN-GB
       #5

    Task Scheduler is one option. For what the OP wants, two tasks are needed: one to be executed 30 minutes after log on, another to be executed 30 minutes after each consecutive unlock.

    Here's how:
    1. In Task Scheduler, select Create Task:

      Force lock windows after set time-2014-09-27_23h33_06.png
    2. Name the task, click Change User or Group:

      Force lock windows after set time-2014-09-28_13h15_09.png
    3. Type the group name Users to Enter the object name to select, click Check Names:

      Force lock windows after set time-2014-09-28_13h16_19.png
    4. Select the group YOUR_COMPUTERNAME\Users, click OK:

      Force lock windows after set time-2014-09-28_13h17_38.png
    5. Switch to Triggers tab, click New:

      Force lock windows after set time-2014-09-27_23h38_21.png
    6. Select Begin the task: At logon

      Force lock windows after set time-2014-09-27_23h40_12.png
    7. Select Any user, select Delay task for and select 30 minutes from the drop down list, click OK:

      Force lock windows after set time-2014-09-27_23h41_13.png
    8. Switch to Actions tab, click New:

      Force lock windows after set time-2014-09-27_23h43_42.png
    9. Select Action: Start a program, type the command rundll32.exe to Program/script field, type the command arguments user32.dll, LockWorkStation to Add arguments, click OK:

      Force lock windows after set time-2014-09-27_23h45_11.png
    10. Click OK to save the task:

      Force lock windows after set time-2014-09-27_23h48_53.png


    This task will lock the computer 30 minutes after any user logs in but thereafter when user unlocks the computer, task will no longer work. For this we need a second task. Repeat the above task creation process, create a similar task except at step 7 change the Begin the task to On workstation unlock:

    Force lock windows after set time-2014-09-27_23h54_29.png

    This second task will take care of locking the computer 30 minutes after each unlock after the initial locking 30 minutes after the log in.

    Should work :).

    Kari
    Last edited by Kari; 28 Sep 2014 at 08:33. Reason: Edited the tasks to make sure they run every time for every user
      My Computer


  6. Posts : 6,285
    Windows 10 Pro X64
       #6

    Kari, another great tutorial. Should be added to the tutorials section.
      My Computer


  7. Posts : 4,049
    W7 Ultimate SP1, LM19.2 MATE, W10 Home 1703, W10 Pro 1703 VM, #All 64 bit
       #7

    Nice


    Ztruker said:
    Kari, another great tutorial. Should be added to the tutorials section.
    Agreed.

    Sorry Kari, I'm not allowed to Rep you.
      My Computer


  8. Posts : 13
    7 64 ultimate
    Thread Starter
       #8

    Thanks a lot, Kari & Ryan2320, I'll try this and update if it works as I wanted.

    Another question, if I may - how do I add a message to the user 1 minute before lock, to let him know that the system will lock in 1 minute?
      My Computer


  9. Posts : 17,545
    Windows 10 Pro x64 EN-GB
       #9

       Note
    Please notice that I have edited my previous post; in my tests the tasks did not run every time for every user.

    I have changed the Step 2 to use a group (Users) instead of individual admin user. As this change requires two additional steps, the steps 3 and 4 were added.

    The tasks will now run every time for every user.


    galili said:
    Thanks a lot, Kari & Ryan2320, I'll try this and update if it works as I wanted.

    Another question, if I may - how do I add a message to the user 1 minute before lock, to let him know that the system will lock in 1 minute?
    OK, then the message. One solution would be to create two additional tasks to display a message every time one of the two tasks we created will be run. However, this would not be very practical. A simpler solution is to use batch files. The below examples will show a message to the user 30 seconds before locking the computer. You can change the time value to whatever you want to.

    A simple but not so elegant solution:
    • Run Notepad as administrator to be able to save directly to protected system folders
    • Create a simple batch file to be saved in the ProgramData folder:
      Code:
      @echo off
      echo The computer will be locked in 30 seconds.
      timeout /t 30
      %windir%\System32\rundll32.exe user32.dll, LockWorkStation
    • In Notepad, select Save As
    • Type %programdata% in Save As dialog's addressbar, hit Enter to access hidden and protected system folder ProgramData:

      Force lock windows after set time-2014-09-28_13h53_27.png
    • Name your batch file, add the .bat extension, select Save as type: All files, click Save:

      Force lock windows after set time-2014-09-28_13h56_03.png
    • Open Task Scheduler and edit both the tasks you created here (in my previous post). Change the Step 9 by changing the Program/Script to %programdata%\LockComputer.bat (or whatever name you gave to batch file), leave the Add arguments field empty, click OK:

      Force lock windows after set time-2014-09-28_14h09_19.png
    • Now when the tasks are run, the user will see a message in Command Prompt and Windows will be locked 30 seconds after the message has been shown:

      Force lock windows after set time-2014-09-28_13h48_49.png


    A bit more elegant solution:
    • Run Notepad as administrator to be able to save directly to protected system folders (we will save all three files below to ProgramData folder)
    • Create a script file:
      Script:
      message "";
        for (
      0WScript.Arguments.lengthi++) 
        {
      message message WScript.Arguments.Item(i) + " ";}
      WScript.Echo(message); 
    • In Notepad, select Save As
    • Type %programdata% in Save As dialog's addressbar, hit Enter to access hidden and protected system folder ProgramData:

      Force lock windows after set time-2014-09-28_13h53_27.png
    • Name your script file as LockMessage, add the .js (Java Script) extension, select Save as type: All files, click Save:

      Force lock windows after set time-2014-09-28_14h23_13.png
    • Still using Notepad as administrator, create a simple two line batch file as follows and save it as LockComputer.bat:
      Code:
      timeout /t 30
      %windir%\System32\rundll32.exe user32.dll, LockWorkStation
    • One more batch: Still using Notepad as administrator, create a simple batch file as follows and save it as RunLockComputer.bat (Red italics = the message text shown to users, edit as you wish):
      Code:
      start /min wscript %programdata%\LockMessage.js Windows will be locked in 30 seconds. All your open applications will remain open, you can unlock the computer with your password and continue working for another 30 minutes.
      start /min %programdata%\LockComputer.bat ^& exit
    • Open Task Scheduler and edit both the tasks you created here (in my previous post). Change the Step 9 by changing the Program/Script to %programdata%\RunLockComputer.bat (or whatever name you gave to batch file), leave the Add arguments field empty, click OK:

      Force lock windows after set time-2014-09-28_15h07_40.png
    • Now when the tasks are run, the user will see a message and Windows will be locked 30 seconds after the message has been shown:

      Force lock windows after set time-2014-09-28_14h32_50.png

    The above script and batch files explained:
    • The script to show message (LockMessage.js) will take any text sent to it with wscript command (which we have in RunLockComputer.bat batch file), and display it on a message window. Command syntax for wscript command is:
      Code:
      wscript Script_Name Text to be sent to that script
    • The first batch file (LockComputer.bat) is the one that executes the Lock Computer command after a 30 second timeout
    • The second batch file (RunLockComputer.bat) is the one we call from the Task Scheduler
      • First it tells to system to run Command Prompt minimized and execute the wscript command to run the message script (lockMessage.js), passing the given text to it as the message which we want to display
      • Then it tells the system to run our first batch file (LockComputer.bat) to lock the computer, also minimized, so the user does not see any open Command Prompt windows but only the message box
      • The ^& exit at the end of the second command closes the minimized Command Prompt when both commands have been executed


    Should run without issues :).

    Kari
    Last edited by Kari; 28 Sep 2014 at 19:04. Reason: Fixed the worst typos, made the script a bit simpler :)
      My Computer


  10. Posts : 13
    7 64 ultimate
    Thread Starter
       #10

    Thanks a lot Kari, I couldn't have asked for a more detailed explanation! I'll try it and update you all.
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 11:45.
Find Us