Microsoft Networking

Remotely Terminate a Remote Desktop Session from the Command Line

You need to connect to a PC using Remote Desktop, but all the available sessions are in use – either by active or disconnected users. So you need to terminate one of those remote RDP sessions, but there is a cache 22 of actually getting into the remote computer to do so.

Solution

This is done from another computer using NET USE and QWINSTA on the command line as a Domain Admin.

Make sure you’re authenticated with remote Windows PC. A simple method is to use NET USE:
C:> net use /user:Administrator \SERVERNAME$
Enter in the Administrator password when prompted and press Enter.
In the Command Prompt, run the following command:
C:> qwinsta /server:SERVERNAME
A list of active and connected Remote Desktop sessions will be displayed. Find the ‘hanging’ connection and its “ID”.
To disconnect and reset the Remote Desktop connection(s) or session(s), use the following command:
C:> rwinsta ID /server:SERVERNAME
For example, if you want to reset the session of “accounting_user1” with a session ID of “3” on the “MYSERVER” server, you would use the following command:
C:> rwinsta 3 /server:MYSERVER
With the RDP session ended, you can now connect to the open slot.

qwinsta is short for “Query Window Station”, and rwinsta is short for “Reset Window Station”.

(Visited 689 times, 1 visits today)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.