Windows server 2022 kill Remote Desktop session

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.

By Mikhail Polenin

i Jupiterimages/Goodshoot/Getty Images

Your copy of Windows only allows a certain number of clients to connect via Remote Desktop to your server. Sometimes you actually end up with a “ghost session” from a previous session that didn’t close properly and prevents you from making a new session. To kill this session, you must acquire privileges on the Microsoft server you run remotely and kill the process using the command line.

Go to your "Start" menu and click “Run.”

Write “cmd” and press “Enter” on your keyboard.

Write “net use \server_ip /USER:your_name password.” This logs you in to the remote server without using RDP, or Remote Desktop protocol. Replace “server_ip” with your server’s IP, “your_name” with your user name and “password” with the password you use to log in.

Write “query session /server:name.” Replace “name” with the server’s name. You get the session ID here.

Write “reset session id /server:server_ip,” replacing “server_ip” with the server’s IP. Do not replace anything else, as all the rest is part of the command. This terminates the active session on your remote server. Try connecting now through Remote Desktop to the new server.

Sometimes, you need to kill a remote desktop session on the server remotely. In this article, we will use qwinsta and rwinsta commands to list and kill the remote desktop session on the server.

Get All Remote Desktop Session

You can run the command qwinsta to get all Remote desktop session on the server. For the example, I want to get all session from the server named wowhvdev1. 

qwinsta /server:wowhvdev1
qwinsta

Kill a Remote Desktop Session

After you get all session list from qwinsta command, you can use rwinsta command to kill a session from the server. This command Enables you to reset [delete] a session on a Remote Desktop Session Host [rd Session Host] server. Before we continue, please remember the “ID” that you get from qwinsta command.

rwinsta /server:wowhvdev1 RemoteID

You can replace the RemoteID with the ID that you get from qwinsta command.

Related

This will let you view all open sessions.

This will kill the listed session.

Business administrators can use Remote Desktop to perform troubleshooting or maintenance on workstations in the office without needing to sign on to the PCs in person. If a user fails to disconnect from a sessions, or if problems occur when attempting to end a Remote Desktop session, an error such as "The Terminal Server Has Exceeded the Maximum Number of Allowed Connections" will appear when you attempt to connect to a remote computer. You can "kill," or disconnect from, crashed or invalid sessions to re-enable the use of Remote Desktop.

  1. Click "Start | Control Panel | Programs | Programs and Features." Click "Turn Windows Features On or Off."

  2. Select "Remote Server Administration Tools" to add the component to the computer. Click "OK."

  3. Click "Start | All Programs | Administrative Tools | Remote Desktop Services." Click "Remote Desktop Services Manager."

  4. Select "Remote Desktop Services Manager" from the left pane. Select "Action" from the menu bar and click "Connect to Computer."

  5. Select "Another Computer" and enter the Internet protocol address of computer running the Remote Desktop Session Host server. Click "OK" to connect to the computer.

  6. Enter the administrative credentials for the computer and click "OK." Select the "Sessions" tab.

  7. Right-click the target connection and choose "Disconnect" from the context menu. Click "OK" to kill the 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ủ Đề