Monday, May 31, 2010

Auto Logout after 1 hour of usage

I recently needed a script to automatically log the user out after 1 hour of computer usage. I came up with a pretty low tech solution. Set a scheduled task to activate on user login that runs a DOS bat script. The bat script sleeps for 57 minutes and then kicks off a reboot with notice. Note: It requires sleep.exe from the Windows Resource Kit tools.

@ECHO OFF
REM ##########################################################################
REM ### by Matt Brown
REM ###
REM ### This Script should be set to Run at Logon via a scheduled task
REM ### - it should be run as an admnistrator and the users that you
REM ### - want to force a logoff should be standard user accounts. 
REM ###
REM ### - Note: Requires sleep.exe from Windows Resource Kit in system32 dir
REM ##########################################################################

REM ### Sleep script for 57 Minutes (in seconds)
SLEEP 3300

REM ### Set the notice to display to the user when shutdown is initiated
SET NOTICE="Your one hour of time has expired. You will be automatically logged off in 3 Minutes"

REM ### Start a shutdown, complete in 180 seconds and give notice to users
SHUTDOWN /r /t 180 /c %NOTICE% /f