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.

Example:

QWinsta /server:202.68.1.51

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:202.68.1.51 1

Once again use the command QWinsta to confirm the user is disconnected successfully.

QWinsta /server:202.68.1.51

Now, you can see the Administrator is not listed in available RDP sessions.

C:> QWinsta /server:202.68.1.51

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

1 thought on “List and Disconnect Remote Desktop Sessions via Command Line”

Leave a Comment