Monday, 20 July 2015

List and Disconnect Remote Desktop Sessions via Command Line

We can list all the Remote Desktop sessions by using the command line tool QWinsta and we can disconnect RDP Sessions using the command RWinsta.
QWinsta /server:<Server name or IP>
Replace the parameter <Server name or IP> with the name or IP address of the Remote Computer.


QWinsta /server:
You will get a list of Remote Sessions with username and session ids in the command window.
List and Disconnect Remote Desktop Sessions via Command Line
From the above output you can easily find what are the RDP sessions are Active from the field STATE. In order to disconnect a user, first, we should find the session id for the corresponding user and you can the session id for the user Administrator is 1.

Use the following command to disconnect the remote session:
RWinsta /server:<Server name or IP> <Session ID>
I have used the below command to terminate the session of the Administrator:
RWinsta /server: 1
Once again use the command QWinsta to confirm the user is disconnected successfully.
QWinsta /server:
Now, you can see the Administrator is not listed in available RDP sessions.
C:\> QWinsta /server:

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc
 rdp-tcp                                 65536  Listen


1 comment:

  1. In your example the user was not disconnected but logged off...