HOWTO – kill windows terminal services sessions remotely


On most systems, these tools are qwinsta.exe and rwinsta.exe, though on some 2003 systems these appear to have been renamed and might be available as query.exe and reset.exe, respectively. Use whichever is available on your machine.
Finding disconnected sessions with qwinsta or query
Run “qwinsta /server:theserver_or_ip” or “query session /server:theserver_or_ip”, using the server name or ip address of the machine you can’t log in to. You’ll get something like the following:
SESSIONNAME  USERNAME  ID  STATE  TYPE  DEVICE
console              0   Conn    wdcon
rdp-tcp              65536  Listen  rdpwd
rdp-tcp#5     auser   1  Active  rdpwd
rdp-tcp#7     another  2  Disc  rdpwd
From this, you can see that users “auser” and “another” are using the two remote Terminal Services connections. Furthermore, the remote desktop client that “auser” is using is still connected to the server, whereas “another” is in a disconnected state, probably the result of closing the remote desktop window instead of logging off.
Killing disconnected sessions with rwinsta or reset
Run “rwinsta sessionid /server:theserver_or_ip” or “reset session sessionid /server:theserver_or_ip”, using the session id obtained above (1 for “auser” and 2 for “another”) and the name or ip address of the server. In this case, you’d probably want to kill session 2, since that user is disconnected anyway.
The command will run without a response, but if you run qwinsta (or query) again, you’ll notice that the session is no longer there. More importantly, if you try and connect to the machine using remote desktop, you’ll get in

at Tuesday, March 13, 2012  

0 comments:

Post a Comment

Powered by Blogger.