This topic describes how to resolve the issue that you cannot connect to a Windows Elastic Compute Service (ECS) instance because of port conflicts.
Problem description
When you connect to a Windows ECS instance by using the built-in Microsoft Terminal Services Client (MSTSC) tool on your on-premises device that runs a Windows operating system or by using Workbench in the ECS console, an error message indicating that the session is disconnected appears. As a result, you cannot connect to the Windows ECS instance. The following figure shows a sample error message for MSTSC.
Cause
The Remote Desktop Protocol (RDP) port of the Windows operating system is used by another process or service. The default RDP port is 3389.
Solutions
You can terminate the process that uses the RDP port or change the RDP port number. Perform the following steps.
Before you perform high-risk operations such as modifying the configurations or data of an Alibaba Cloud instance, we recommend that you check the disaster recovery and fault tolerance capabilities of the instance to ensure data security. For information about snapshots, see Overview.
If you granted access permissions on or submitted sensitive information (such as usernames and passwords) in the Alibaba Cloud Management Console, we recommend that you modify the information at the earliest opportunity.
Connect to the Windows ECS instance by using Virtual Network Computing (VNC).
For more information, see the Windows instance section of the "Connect to an instance by using VNC" topic.
View the process that uses the RDP port. In this example, Windows Server 2022 is used.
Open the Command Prompt window.
In the Command Prompt window, run the
netstat -ano|findstr "3389"command to identify the process that uses port 3389.
Run the
tasklist /FI "PID eq <PID that you obtained in the previous step>"command to view the process details. Replace the PID of the process to be terminated with the actual PID. In this example, thetasklist /FI "PID eq 4176"andtasklist /FI "PID eq 7164"commands are run. In the command output, svchost.exe is the RDP process, and python.exe is the process that uses port 3389.
Method 1: Terminate the process that uses port 3389.
Run the
taskkill /PID <PID of the process to be terminated> /Fcommand. Replace the PID of the process to be terminated with the actual PID. In this example, thetaskkill /PID 4176 /Fcommand is run.ImportantTo prevent impacts on your business, we recommend that you fully understand the features of a process before you terminate the process. Stopping a key business or system process may cause a business interruption, a system crash, or an instance connection failure.
Use MSTSC or Workbench to reconnect to the Windows ECS instance.
Method 2: Change the RDP port number.
Open Registry Editor.

Navigate to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp path and right-click the PortNumber parameter. In the dialog box that appears, change the Value data value to the port number that you want to use.
Navigate to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp path and right-click the PortNumber parameter. In the dialog box that appears, change the Value data value to the port number that you want to use.
NoteYou must specify the same Value data value for the PortNumber parameter of the tcp and RDP-Tcp registry keys.
The Windows operating system automatically recognizes the new RDP port number. Open the Services window.
Right-click Remote Desktop Services and then select Restart.
Configure security group rules to allow traffic on the new RDP port.
For information about how to add a security group rule, see Add a security group rule.
Use MSTSC or Workbench to reconnect to the Windows ECS instance.