Kill Remote Desktop session Windows 10

Today I marking the official start of my new blog series entitled quick tips. For this series I will focus on simple things that developers might find handy; from scripts, to commands, hot-keys and other tips that, maybe you already know, maybe not. Most of the posts from this series, will be direct, quick and simple. Personally, I just want to share the notes I have been gathering though the years. For my first quick tip post, I will show how you can list all remote desktop connections, and kill a particular session.

Sometimes you might encounter the following error when trying to establish a remote desktop connection: ” The terminal server has exceeded the maximum number of allowed connections”. This happens because there’s a maximum limit of allowed remote connections. On top of that, maybe somebody forgot to logoff their remote desktop connection, and their inactive session might occupying a spot that you could use.

Let’s begin by opening the command prompt [or PowerShell] using: [Win] + [r]; type cmd [or powershell] and press [enter]

Now we are going to use qwinsta to [paraphrasing documentation] “ Display information about Remote Desktop Services sessions.”. If you use the command without any additional arguments, information about your local computer sessions will be display. However, most likely you want to target a remote computer; to do that simply enter the server name, or machine IP, using /SERVER: argument. Example qwinsta /SERVER:mywebserver or qwinsta /SERVER:192.168.1.15

To disconnect, or reset a particular session, just use rwinsta and supply the server name and the session Id you want to reset. Session Ids are display on qwinsta resulting output. Example rwinsta /SERVER:mywebserver 70

For more information about this two command, please take a look at their TechNet documentation pages: qwinsta ; rwinsta.

This will let you view all open sessions.

This will kill the listed session.

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:[ServerIP/Hostname]

Example:

qwinsta /server:192.168.40.1

qwinsta /server:myServer.Contoso.com or myserver.contoso.local

Output of Command

C:>qwinsta /server:myServer.contoso.com

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.

#KillRemoteSession #RemoteDesktopSession #QWinSta #RWinSta #LogoffRemoteSession #WindowsServer #RDPSession #MSTSCSession #Server

Video liên quan

Chủ Đề