-1

Looking for a script that can end idle session shares on a Server 2008 R2.

If sessions are left open for too long there are programs that fail to update due to files/folders being open.

I am looking to run a script that will close idle sessions after a given time period.

I do not want to kill active sessions or use a kill all command just to close idle sessions after say 12 hours.

Thanks you for your help in advance.

Andrew

  • I think you need to define what "session" means. Do you mean "file sessions" as displayed in the management console? – Avery Payne Jul 03 '14 at 19:59

2 Answers2

2

Depending on your environment you could also configure group policy. Use settings in the following locations:

Computer Configuration\Policies\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Session Time Limits

User Configuration\Policies\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Session Time Limits

You could also do this through the remote desktop host configuration utility on a per host basis. It should be located in Administrative Tools.

For more info, review the following tech net article on the subject: http://technet.microsoft.com/en-us/library/cc754272.aspx

Hope that helps.

Philosophene
  • 202
  • 1
  • 12
0

We are using the below script in a Server 2008 environment, but I'm sure it would work for R2 as well. Basically, it loops through open terminal sessions and if the session has been idle for more than 59 min., it ends the session. Batch file:

@echo ON
setlocal ENABLEDELAYEDEXPANSION

for /F "Tokens=1-8*" %%a in ('net session^|Find "\\"') do (
     call :sess %%a %%b %%c %%d %%e %%f %%g %%h %%i
     @echo !comp! !idle!
)
endlocal
goto :EOF

:sess
set comp=%1
set idle=00:00:00
:sessL
shift
if {%1}=={} goto sessT
set idle=%1
goto sessL

:sessT

for /f "Tokens=1 Delims=:" %%x in ('@echo %idle%') do (
    if "%%x" GEQ "00" net session %comp% /DELETE /Y
)