How to kill RDP session remotely ?

Category:

Use the command line tools to identify the open sessions and kill one of them. There are two tools, qwinsta and rwinsta. If you run "qwinsta /?" from a command shell, you will get the following:

qwinsta /?

Display information about Terminal Sessions.
QUERY SESSION [sessionname | username | sessionid]

[/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER]
  sessionname         Identifies the session named sessionname.

username Identifies the session with user username.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).
/MODE Display current line settings.
/FLOW Display current flow control settings.
/CONNECT Display current connect settings.
/COUNTER Display current Terminal Services counters information.



If you run "rwinsta /?", you get the following:


rwinsta /?

Reset the session subsytem hardware and software to known initial values.

RESET SESSION {sessionname | sessionid} [/SERVER:servername] [/V]

sessionname Identifies the session with name sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server containing the session (default is current).
/V Display additional information.



For the sample server abc, you would run "qwinsta /server:abc"

Output


 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE

console 0 Conn wdcon
rdp-tcp 65536 Listen rdpwd
abcd 1 Disc rdpwd
rdp-tcp#93 gates 3 Active rdpwd


From that output, we can take one of the IDs that was returned for the remote sessions and use rwinsta to kill that session. You would use something like:


rwinsta 1 /SERVER:abc


And that will terminate that session, allowing you to open a new session. You will need admin rights to run that command, but if you are using the admin terminal service connections to the server, then you would already have the necessary access rights to the server.


There is a third option, you can connect to the console session. This is the bonus option that I had referred to earlier. This is the session that you would get if you were physically in front of the server and were logging in on the server's mouse and keyboard. You can specify the console session as a command line parameter to the remote desktop client, mstsc.exe. The following syntax can be used to connect to the console session of a server:


mstsc /console

That feature will work with Server 2003 and later. On some machines, qwinsta and rwinsta may have been renamed to query.exe and reset.exe, respectively.

Comments (0)

Post a Comment