Enable or Disable RDP via Command Line (Windows)

Problem

Allow or prohibit Remote Desktop connections to your Windows machine through Command Prompt or PowerShell.

tl;dr

Run the required command from shell with Administrative privileges.

To enable RDP:
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
To disable RDP:
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 1 /f

Solution

Sometimes, you may with to allow Remote Desktop Protocol so you can manage your computer or server remotely. Unfortunately, you may not be logged in to Windows itself, or do not have physical access to the desktop. For example, you are pre-configuring a build for deployment, you are repairing a system while in recovery mode, or you only have SSH access to your server, but no KVM. In these situations, it is still possible to enable (or disable) RDP by setting a registry value.

You must be logged in to a shell prompt (cmd or PowerShell) that has full administrative access to do so. Recovery mode prompt has admin access already. Command prompt inside Windows can be run as Administrator by right-clicking it and selecting "Run as Administrator." If you are using PowerShell, whether via SSH, or locally, run the following command to elevate your privileges:

Start-Process powershell -Verb runAs

Once you finally have Admin privileges, enter one of these two commands to modify the required registry key.

To enable RDP:
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
To disable RDP:
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 1 /f


Was this article helpful?

mood_bad Dislike 19
mood Like 32
visibility Views: 85920