How to enable, launch, connect and kill RDP from command line

Learn how to use CMD and PowerShell to enable RDP, connect to servers, and close ongoing connections.

How to enable, launch, connect and kill RDP from command line

The command line may not be the first point of call for many Windows RDP users, but it has its uses. Knowing how to enable, launch, and kill RDP from the command line is incredibly useful for automating setup across several computers. This guide will explain how to do all of these step-by-step.

How to enable RDP from the command line

Before attempting other commands, ensure that RDP is activated on both your chosen system and the remote server. In Windows, RDP can be enabled via two command-line methods: the Command Prompt (CMD) and PowerShell.

How to enable RDP with CMD

The following should work on both your client and host PC:

  1. Press Start and type "CMD"
  2. Right-click on "Command Prompt" and choose "Run as Administrator"
  3. Paste the following command to enable RDP in your registry and press Enter.
`reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f`

If you get the message "Updated 3 rule(s)", then RDP is successfully turned on.

You may also need to allow it through the firewall with netsh advfirewall firewall set rule group="remote desktop" new enable=Yes

How to enable RDP using PowerShell

PowerShell users have a similar command:

  1. Press Start and type "PowerShell"
  2. Right-click on PowerShell and choose "Run as Administrator"
  3. Enter this command and press Enter to enable RDP in the registry:
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0

You may need to allow RDP through the firewall using Enable-NetFirewallRule -DisplayGroup "Remote Desktop".

How to launch RDP from the command line


You can run RDP from the command line to automatically start the tool on startup, with the possibility to even connect to open a connection to your host PC with a command.

The command to open the RDP application in CMD is:

mstsc /f

Alternatively, you can open an RDP console session using mstsc /console

Or, more conveniently, open RDP and connect directly to your server with:

mstsc /v:your.server.ip

This will open the RDP application to the logon screen.

How to kill RDP from the command line

You can disconnect from or kill an RDP session from the command line using TSDISCON, a built-in tool for this purpose.

The command syntax is as follows:

tsdiscon <Session ID> /server:<your.server.ip or domain name>

The query session command can be used to find the session ID of the RDP connection. To query, you'll need Windows 10 Pro or higher.

The final command would look something like this:

tsdiscon 3 /server:123.45.67.89

The session will be terminated as soon as you press Enter.

Killing an RDP connection with the logoff command

Another alternative is using the logoff command, which has the same effect as tdiscon and similar syntax. Run:

logoff <session ID> /server:<your.server.ip or domain name>

This will, again, disconnect the user instantly.

Need a Windows RDP server? Sign up here and launch one instantly.