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!

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
Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. Put simply, Windows 7 is not responsible for any battery life issues ...

Getting your iPhone to Sync with Exchange 2003

Follow these steps to use an iPhone with Exchange. ...


Related Events 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.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement