0

I need some script to be able to kill terminal sessions in our server.

Basically, some users are connecting through an application via Terminal Services. When they close the application, it usually triggers the disconnection and closure of the Terminal Services.

On some occasions, the users instead of closing the application, closes the terminal service. This leaves the terminal session hanging since the application is still running.

Is there a script available which would be able to detect those hanging terminal services, including the application which is running inside it?

Appreciate any help on this. Thanks.

3 Answers3

2

Please try the below mentioned Script:

REM @echo off
REM This batch file will read a list of computers in 'computers.txt', query (qwinsta)
REM the sessions that are currenlty disconnected, then pass them to
REM reset them using (rwinsta).  It might not be as graceful as a logoff 
REM but it works.

REM Mike Stone
REM 06/19/2008

For /F %%A in (computers.txt) do (
    for /f "tokens=2" %%i in ('qwinsta /SERVER:%%A ^| find /i "disc"') do echo %%i | rwinsta %%i /SERVER:%%A /V
)
Ben Pilbrow
  • 11,995
  • 5
  • 35
  • 57
Gaurav Singh
  • 497
  • 2
  • 13
  • Also refer below URL it might be helpful:http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21183183.html – Gaurav Singh Dec 09 '10 at 22:13
  • Also refer to limit the time : http://gallery.technet.microsoft.com/scriptcenter/en-us/f883c6e0-6874-4095-9fd0-3b28d44a7a3d – Gaurav Singh Dec 09 '10 at 22:15
  • You could also use tskill.exe instead of rwinsta – mfinni Dec 09 '10 at 22:19
  • we try to avoid linking to the "hyphen-site" over here, as their site goes against everything that we stand for. If you need to, please quote the content of the post you're linking to in your answer, as a lot of people can't or don't know how to, read the answers on that site. – Mark Henderson Dec 10 '10 at 01:48
2

Use the idle timeout and disconnect timeout in Terminal Services.

Keith Stokes
  • 927
  • 6
  • 7
0

Assuming that you're running Terminal Services in a domain (and even if you're not), there are a number of GPO settings (or local settings) to control RDP sessions. Seems like using those settings is preferred over reinventing the wheel. Why write and run a script when you can configure Group Policy to do the work for you?

joeqwerty
  • 108,377
  • 6
  • 80
  • 171