Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

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
)
share|improve this answer
    
Also refer below URL it might be helpful:experts-exchange.com/Programming/Languages/Visual_Basic/… –  Gaurav Singh Dec 9 '10 at 22:13
    
Also refer to limit the time : gallery.technet.microsoft.com/scriptcenter/en-us/… –  Gaurav Singh Dec 9 '10 at 22:15
    
You could also use tskill.exe instead of rwinsta –  mfinni Dec 9 '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 1:48

Use the idle timeout and disconnect timeout in Terminal Services.

share|improve this answer

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?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.