Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Force lock windows after set time

27 Sep 2014   #1
galili

7 64 ultimate
 
 
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 System SpecsSystem Spec
.
27 Sep 2014   #2
frankiemountain

win7 64 bit
 
 

Use parental controls. Only works on user accts, not admins.
My System SpecsSystem Spec
27 Sep 2014   #3
galili

7 64 ultimate
 
 

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 System SpecsSystem Spec
.

27 Sep 2014   #4
Ryan2320

Windows Seven x64
 
 

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 System SpecsSystem Spec
27 Sep 2014   #5
Kari

Microsoft Community Contributor Award Recipient

 

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


My System SpecsSystem Spec
27 Sep 2014   #6
Ztruker

Windows 10 Pro X64
 
 

Kari, another great tutorial. Should be added to the tutorials section.
My System SpecsSystem Spec
27 Sep 2014   #7
lehnerus2000

W7 Ultimate SP1, LM18 MATE, W10IP VM, W10 Home, #All 64 bit
 
 
Nice

Quote   Quote: Originally Posted by Ztruker View Post
Kari, another great tutorial. Should be added to the tutorials section.
Agreed.

Sorry Kari, I'm not allowed to Rep you.
My System SpecsSystem Spec
28 Sep 2014   #8
galili

7 64 ultimate
 
 

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 System SpecsSystem Spec
28 Sep 2014   #9
Kari

Microsoft Community Contributor Award Recipient

 

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


Quote   Quote: Originally Posted by galili View Post
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


My System SpecsSystem Spec
28 Sep 2014   #10
galili

7 64 ultimate
 
 

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

 Force lock windows after set time




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Num Lock, Caps Lock and Scroll Lock all lights up (not blinking)
For some time now, i have been experiencing that my Num Lock, Caps Lock and Scroll Lock all lights up (not blinking) all at the same time, I tried to google it but i can not find any solutions or explanations for it. Does anyone know if it is bad? and what is causing this? I am having a wired...
Hardware & Devices
Logitech Driving Force EX - Force Feedback Motor Query
So... Before anyone tells me to send it to Logitech for repairs, I should mention that there are none that I know of in my area, and I'm not willing to pay R300 (ZAR) postage to send a big box 600km away to get my wheel 'checked'. Other than that, it's already nearly 3 years old and way out of...
Hardware & Devices
How to get the current time on the lock screen?
I need some sort of registry hack or software to get the current time somewhere on the sign-in screen. Please help
Customization
Caps lock, num lock, scroll lock screen messages
Hi, how to disable Caps lock, num lock, scroll lock screen messages? I have desktop pc with two keyboards usb and bluetooth. Also TOSHIBA Bluetooth Stack software, but in device manager: keyboard > hid keyboard device both using microsoft drivers. And I dont have any software installed...
General Discussion
screen lock = force re-boot
I was sailing smooth but last 2 days I am getting random screen locks and then have to force re-boot. I looked at my minidump file "last modified date" and it shows 7/30/2010 - does that mean that windows did not crash - but the screen locked up anyway??? Also noticed that tonight when it...
BSOD Help and Support


Our Sites

Site Links

About Us

Find 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 05:33.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App