Updated: Aug 29
Article No :: KB00007
In the Windows Servers, by default, there are only two remote desktop sessions allowed (until you have taken an RDP license). In multiple situations, you find that you can’t connect/login into the server via RDP/MSTSC because two sessions are already active or in disconnected mode. You get the error msg "Remote Desktop Disconnected", "This computer can’t connect to the remote computer."
Permission/Access required - You must be the part of the local administrator group of the remote server to kill/reset the disconnected or active sessions.
Applies to - Windows Server 2016, Windows Server 2012 R2, Windows Server 2012, Windows Server 2008 R2, Windows Server 2008
Query the Remote Server for Current Terminal Sessions
QWinSta - Displays information about sessions on a Remote Desktop Session Host (RD Session Host) server
First, we query to list the sessions on the remote server.
Command for Query the Server Sessions is
qwinsta /server:myServer.Contoso.com or myserver.contoso.local
Output of Command
SESSIONNAME USERNAME ID STATE TYPE DEVICE
0 Disc rdpwd
ica-tcp 65536 Listen wdica
rdp-tcp 65537 Listen rdpwd
console 16 Conn wdcon
ica-tcp#966 avijitd 10 Active wdica
ica-tcp#969 deepakk 1 Active wdica
Note: Please take a note of the session ID from the Query command. In the above example, if i have to disconnect the session of User "avijitd" then the session id is "10".
Logoff/Kill the Remote Desktop Sessions
RWinSta - Enables you to reset (delete) a session on a Remote Desktop Session Host (rd Session Host) server.
Command for Release the Server Sessions
rwinsta [Session ID] /server:[Server IP]
Example: We will kill/logoff the remote session of user "avijitd" whose session ID is "10"
rwinsta 10 /server:192.168.40.1
rwinsta 10 /server:myServer.Contoso.com or myserver.contoso.local
Note: RWinsta command does not return anything.
Some good books related to Windows Hacks and Microsoft Azure Cloud. Do check it out.