Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

March 09, 2005 12:00 AM

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

Windows IT Pro
InstantDoc ID #83178
Rating: (0)

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%



Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.