How to Open an RDP Connection via CMD in Windows 11

Published by Nyau Wai Hoe - Updated on

The Remote Desktop Protocol (RDP) is a proprietary protocol developed by Microsoft. It provides users with a graphical interface to connect to another computer over a network connection. Users often interact with this feature through the built-in Remote Desktop Connection app (mstsc.exe) on Windows systems. However, power users and administrators may prefer to use the command line for its flexibility and scripting capabilities.

In this article, we will delve into the use of the command prompt to open an RDP connection, enabling remote access, and managing Remote Desktop sessions in Windows 11.

How to Open an RDP Connection via CMD in Windows 11

Opening an RDP connection from Command Prompt

The command prompt on Windows offers a quick and efficient way to establish an RDP connection. The mstsc command, which stands for Microsoft Terminal Services Client, is the key to this process.

After opening the command prompt, you can type the following command to start a remote connection:

mstsc /v:yourRemoteComputer

Open RDP connection in Command Prompt

In this command, “yourRemoteComputer” should be replaced with the IP address or hostname of the computer you aim to connect to. This direct approach allows for rapid connections without the need to navigate through multiple user interfaces.

Also see: How to Remote Desktop Over The Internet in Windows 11

Running remote desktop command

The mstsc command comes with several switches that can customize your Remote Desktop sessions. For example, the /f switch starts Remote Desktop in full-screen mode, and the /admin switch starts a session with administrative privileges.

mstsc /f /v:yourRemoteComputer

Start RDP session in full-screen mode

You can see a full list of the available switches by typing the following command in the command prompt:

mstsc /?

Useful tip: Windows 11: Check Who is Logged in Remotely or Locally

MSTSC command prompt usage

Connecting to the console session of a remote computer

The mstsc /console command or mstsc /admin in newer versions of Windows, is a useful tool when you want to connect to the console session of a remote computer. The console session is typically session 0, and it is the session that is displayed at the physical computer.

Using the console session can be useful in certain situations. For example, some software applications can only run in the console session, or some administrative tasks may require access to the console session.

Here’s how to use the mstsc /admin command:

  1. Open the command prompt.
  2. Type the following command and press Enter:
    mstsc /admin /v:yourRemoteComputer

    Replace “yourRemoteComputer” with the name or IP address of the remote computer you want to connect to.

Remote Desktop console session with admin

This command will start a Remote Desktop session to the console session of the specified remote computer.

Please note that using the /admin parameter to connect to a remote computer will not create a new Remote Desktop session. Instead, it will connect you to the console session of the remote computer, which may be in use. Therefore, be cautious when using this command to avoid disrupting a session in progress.

Linked issue: Windows 11 Remote Desktop “An authentication error has occurred”

Starting and stopping a remote desktop session

Managing Remote Desktop sessions is a crucial aspect of remote system administration. As previously discussed, the mstsc command is used to start a session. To end a session, you can simply close the Remote Desktop window, but you can also use command line options for increased control.

The logoff command, when used in the command prompt of the remote system, allows you to end a session. You need to follow logoff with the session ID to specify which session to end. The session ID can be found by running the query session command.

logoff SessionID

Related resource: How to Install Telnet via CMD or PowerShell in Windows 11

Accessing remote desktop using RDP file

Microsoft’s Remote Desktop service allows the creation of .rdp files, which are essentially configuration files that store settings for Remote Desktop sessions. An .rdp file can include information like the target hostname, display settings, and other session configurations. This feature is particularly useful when you frequently connect to a remote computer with specific settings, as it eliminates the need to enter the configurations manually each time.

Here’s a simple step-by-step guide on how to create an .rdp file:

  1. Open the Remote Desktop Connection application by typing mstsc in the command prompt or search bar and press Enter.
  2. In the Remote Desktop Connection window, enter the name or IP address of the remote computer you want to connect to in the “Computer” field.
  3. Click on “Show Options” to reveal more settings. Here, you can enter your username, adjust display settings, and configure other preferences for your Remote Desktop session.
  4. Once you’ve entered your credentials and configured your settings, click on “Save As” under the Connection settings.Accessing remote desktop using RDP file
  5. In the “Save As” window, navigate to the location where you want to save the .rdp file. Enter a name for the file and click “Save”.

Now you have an .rdp file that you can use to quickly start a Remote Desktop session with your preferred settings.

To use the .rdp file, you just need to type the following command in the command prompt, replacing “C:\file.rdp” with the actual path and filename of your .rdp file:

mstsc C:\file.rdp

How to open RDP file in Command Prompt

This command will open a Remote Desktop session using the settings stored in the specified .rdp file. If you saved your credentials in the .rdp file, it will automatically log you into the remote computer; otherwise, it will prompt you to enter your password.

Enabling remote access in Windows 11

Before you can establish a remote connection to a computer, you need to ensure that it has Remote Desktop enabled. While this can be achieved through the user-friendly Settings application in Windows 11, power users may prefer the command line approach using PowerShell.

To enable Remote Desktop via PowerShell, you need to open a PowerShell prompt with administrative privileges first. You can do this by typing “PowerShell” into the Windows Search bar, right-clicking on the Windows PowerShell app, and selecting “Run as administrator.”

Once in PowerShell, the command to enable Remote Desktop is:

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0

This command changes a registry key that controls the enabling and disabling of Remote Desktop.

Enabling remote access in Windows 11

Executing commands on a remote system

Running commands on a remote system can be crucial for system administration. Windows provides the PsExec tool, a part of the Sysinternals suite, to execute commands on a remote system. Once you’ve installed PsExec, you can run a command on a remote system by typing the following command:

psexec \\remoteComputer command

In this command, “remoteComputer” should be replaced with the name of the remote computer, and “command” with the command you wish to execute.

Executing commands on a remote system


In this guide, we have explored various facets of using the command prompt for Remote Desktop operations in Windows 11. From establishing a basic RDP connection to more advanced tasks like accessing the console session of a remote system, command line operations provide an efficient and flexible way to manage remote connections.

The power of command line operations shines in situations where you need to automate tasks, perform bulk operations, or work on systems without a graphical interface. .rdp files offer a useful way to save session settings, and tools like PsExec and the /admin switch of mstsc give you advanced control over remote systems.

However, remember to use these commands responsibly to avoid causing unnecessary system interruptions or exposing the system to security risks. Always ensure your RDP connections are secure and only give access to trusted users.

Nyau Wai Hoe
Nyau Wai Hoe is the Founder and Chief Editor of With a degree in software engineering and over 12 years of experience in the tech support industry, Nyau has established himself as an expert in the field, with a primary focus on the Microsoft Windows operating system. As a tech enthusiast, he loves exploring new technologies and leveraging them to solve real-life problems.

Share via
Copy link