Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 



JSI Tip 9130. How can I schedule a user log off after nnn minutes of inactivity, on all my domain workstations?

RSS
Subscribe to Windows IT Pro | See More Domains Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!


9130 » How can I schedule a user log off after nnn minutes of inactivity, on all my domain workstations? 09-Mar-05


I have scripted IOff.bat to schedule a user log off after nnn minutes of inactivity, on all the domain workstations.

IOff.bat uses PsShutdown.exe, which it will copy to each workstation. To schedule the task, IOff.bat uses SchTasks.exe, which is built into Windows XP, Windows Server 2003, and later. It is best to run IOff.bat from Windows XP, or Windows Server 2003, while logged on as a member of the Domain Admins group, but you could run it from your Windows 2000 workstation if you implement tip 5335.

The syntax for using IOff.bat is:

IOff IdleMinutes folder

Where IdleMinutes is the number of minutes, between 1 and 999, that the user must be idle before they are logged off, and folder is the path to  PsShutdown.exe on the workstation that runs IOff.bat. PsShutdown.exe will be copied to this path on all the workstations. If folder does NOT exist on a member computer, it will be created.

NOTE: IOff.bat does NOT schedule the IOff task on the workstation that runs IOff.bat.

NOTE: IOff.bat uses NETDOM.EXE to enumerate domain workstations. NETDOM.EXE is built into Windows XP and later, or installed on the Windows 2000 computer that runs IOff.bat, from the Support Tools on the operating system CD-ROM.

IOff.bat contains:

@echo off
if {%2}=={} @echo Syntax: IOff IdleMinutes folder&goto :EOF
setlocal
set wrk=%1
set /a IM=1000%wrk%%%1000
if "%wrk%" NEQ "%IM%" @echo Syntax: IOff %wrk% not valid, 1-999&endlocal&goto :EOF
if %IM% LSS 1 @echo Syntax: IOff %wrk% not valid, 1-999&endlocal&goto :EOF
if %IM% GTR 999 @echo Syntax: IOff %wrk% not valid, 1-999&endlocal&goto :EOF
set folder=%2
set lcl=%folder%
set lcl=%lcl:"=%
if not exist %folder% @echo IOff - %folder% NOT found.&endlocal&goto :EOF
set folder=%folder::=$%
set folder=%folder:"=%
set fnd1=findstr /V /I /L /C:"List of workstations with accounts in the domain:"
set fnd2=findstr /V /I /L /C:"The command completed successfully."
set fnd3=findstr /V /I /L /C:"%ComputerName%"
for /f "Tokens=*" %%c in ('netdom query WORKSTATION /DOMAIN:%USERDNSDOMAIN%^|%fnd1%^|%fnd2%^|%fnd3%') do (
 set computer=%%c
 call :doit
)
endlocal
goto :EOF
:doit
if not exist \\%computer%\c$ @echo %computer% NOT available&goto :EOF
if not exist \\%computer%\%folder% MD \\%computer%\%folder%
call :cpy>nul 2>&1
call :sch
goto :EOF
:cpy
copy %lcl%\PsShutDown.exe \\%computer%\%folder%\*.*
goto :EOF
:sch
@echo SCHTASKS.exe /Create /RU "SYSTEM" /SC ONIDLE /I %IM% /TN "IOff" /TR "%lcl%\PsShutdown.exe -O -F" /S %computer%
SCHTASKS.exe /Create /RU "SYSTEM" /SC ONIDLE /I %IM% /TN "IOff" /TR "%lcl%\PsShutdown.exe -O -F" /S %computer%



End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Windows 7 Sets Sales Record

Microsoft CEO Steve Ballmer described Windows 7's first ten days of sales as "fantastic" while in Japan yesterday. ...


Related Events WinConnections and Microsoft® Exchange Connections

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Related Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement