The Remote Desktop Connection (RDC) tool, also known as Microsoft Terminal Services Client (MSTSC), allows a user to connect to another computer remotely over the network using the Remote Desktop Protocol (RDP). Most users use this tool via its Graphical User Interface (GUI) which is convenient to use, but this article focuses on using the Remote Desktop via the command line.
Connecting to other computers using RDC through the command line allows you to control different settings and preferences of the connection. Windows allows a user to use certain switches to predefine the settings before the connection is made. For example, you can define the name or IP address of the remote computer, or adjust the RDC window size even before running the tool.
Learn how to enable RDC in Windows 11.
Table of Contents
Let us help you become aware of the switch options and how you can use them to configure your RDC connections.
MSTSC commands and switches
The conventional way to open the RDC in Windows is by searching for “Remote Desktop Connection” or “RDC” in Run and open the tool.
This then opens the RDC tool where you can enter the name of IP address with port number (optional) of the remote computer that you want to connect to.
Most of you would already be aware of this method.
This section covers the possible commands and switches that you can use with RDC via the command line. We shall start with the most basic ones and then continue.
Launch RDC from Run
The very basic command to run Remote Desktop Connection from the command line is via Run. Simply type in the following in Run and hit Enter.
mstsc
Running this will open the RDC with a blank text field. However, with the addition of a few switches, you can change the settings and preferences of the RDC connection. Let us continue forward with a few examples.
Use RDC to connect via console
Although RDC fully supports GUI, you can also connect to remote machines through a console. This will help in case you wish to continue the session that you got disconnected from earlier. In contrast, a regular GUI-based RDC session creates a new session each time you connect to the same machine.
Use the following command to connect to a remote computer via console:
mstsc /console
Launch RDC with IP address
You can also launch RDC along with the IP address of the machine to connect it with. If the port on the machine is changed from the default value, you can also add the port number. Use the following commands to do so:
mstsc /v:IPAddress
mstsc /v:IPAddress:PortNumber
Replace IPAddress with the complete IP address of the remote computer that you want to connect with, and PortNumber with the port number if changed from its default value.
Launch RDC with computer name
You can also connect to the remote computer by its unique computer name. The switch used for this is the same one used with the IP address and port number in the steps above.
mstsc /v:ComputerName
Replace ComputerName with the unique name of the remote device that you can find in its settings or properties.
Launch RDC in full-screen mode
You can also launch the RDC connection in full-screen mode. Here is how:
mstsc /f
These switches can be combined into a single command to execute an RDC connection to your preferences. Here is an example:
mstsc /f /v:192.168.10.122:8002
MSTSC commands and switches
There are more commands and switches you can use with mstsc command-line to adjust your settings for the connection beforehand. Here is the complete list:
<connectionfile> | For a .rdp file required to make a connection (if applicable). |
/v: | IP Address or computer name of the remote computer. |
/g: | IP Address or device name of a Remote Gateway Server (if applicable). |
/admin | To establish a connection with administrative privileges. |
/f | View the Remote Desktop Window in full-screen mode. |
/w: | To specify the width of the Remote Desktop Window. |
/h: | To specify the height of the Remote Desktop Window. |
/public | Run the Remote Desktop Connection publicly (less secure). |
/span | To match the width and height of the Remote Desktop with the local desktop. |
/edit <connectionfile> | To edit a .rdp file. |
/multimonTo make the monitor layout of the Remote Desktop Services session identical to the client-side configuration. | |
/restrictedAdmin | Connect to the remote PC in Restricted Administration mode. The credentials are not sent to the remote PC in this mode, protecting you if you connect to a compromised PC. |
/remoteGuard | Connect your device to a remote device using the Remote Guard, which prevents sending credentials to a remote PC. |
/prompt | To prompt you to put in credentials to connect to the remote PC. |
/shadow: | The ID of the session that you want to connect to. |
/control | Give control of the session when shadowing. |
/noConsentPrompt | To allow shadowing without user consent. |
/migrate | Migrate legacy connection files created with Client Connection Manager to new .rdp connection files. |
/? | To get help in the command prompt. |
These switches can have the following syntax in either Run or the Command Prompt:
mstsc [<connection file>] [/v:<server[:port]>] [/g:<gateway>] [/admin] [/f] [/w:<width> /h:<height>] [/public] | [/span] [/multimon] [/edit "connection file"] [/restrictedAdmin] [/remoteGuard] [/prompt] [/shadow:<sessionID> [/control][/noConsentPrompt]]
The parameters in the alligator brackets (< and >) are variables that you can adjust according to your preferences.
Troubleshoot RDC via command line
You can also troubleshoot Remote Desktop services through the command line. For example, if you are unable to connect to a device using the GUI RDC but have access via console, you can check whether there are any configurations to be made that will connect you via GUI successfully.
Check if RDP is enabled from Command prompt
Learn how to enable RDP remotely.
You can run the following command to check the status of your device if RDP is enabled or disabled:
netstat /p tcp /a | findstr 3389
If the results come back as “Listening,” it means that RDP is enabled.
Check if RDP is enabled from PowerShell
Another method to check whether RDP is enabled is through Windows PowerShell. You can run the following commands in PowerShell and it will tell you whether the service is available or not.
if ((Get-ItemProperty "hklm:\System\CurrentControlSet\Control\Terminal Server").fDenyTSConnections -eq 0) { write-host "RDP is Enabled" } else { write-host "RDP is NOT enabled" }
If the script returns “RDP is enabled,” it means that it is.
Frequently Asked Questions
What is MSTSC?
Microsoft Terminal Services Client (MSTSC) is a tool that allows a user to remotely connect to another device over the network as if they were physically present on the remote device.
How to open Remote Desktop from the command line?
You can open the Remote Desktop Connection window from Run or Command Prompt using mstsc. You may also add switches like /v and /f to control the connection’s arguments.
How to add username and password to mstsc command line?
You cannot add a username or password directly to the mstsc command. However, you can store the credentials in a generic key against the machine you want to connect to using these 2 commands:cmdkey /generic:"<server>" /user:"<user>" /pass:"<password>"
mstsc /v:"<server>"
Is the RDP and RDC the same?
Remote Desktop Connection (RDC) is a tool used to establish a remote connection between devices. Remote Desktop Protocol (RDP) is the technology that RDC uses to create this remote connection.
The Remote Desktop Protocol (RDP) is something Microsoft made since years ago. It lets you see and use another computer from yours over a network. Most people use the Remote Desktop Connection app (mstsc.exe
) that comes with Windows. But, if you like doing things with command lines, because you want more control or to write scripts (for example, to automate stuffs), there’s a way for that too.
In this guide, we’re going to look at how to use the command line to make an RDP connection, turn on remote access, and handle Remote Desktop sessions on Windows 11.
How to start an RDP connection with Command Prompt
The command prompt in Windows is a speedy way to start an RDP connection. You’ll use the mstsc
command, which stands for Microsoft Terminal Services Client, to do this.
After opening the command prompt, type this to begin a remote connection:
mstsc /v:yourRemoteComputer
Replace “yourRemoteComputer” with the IP address or computer name you’re connecting to. This way is quick because you don’t have to click through lots of menus.
Also see: How to Remote Desktop Over The Internet in Windows 11
Using the command line for remote desktop
The mstsc
command has many options to change how your Remote Desktop sessions work. For instance, /f
makes it full screen, and /admin
gives you admin rights.
mstsc /f /v:yourRemoteComputer
To see all options, type this:
mstsc /?
Handy tip: Windows 11: Check Who is Logged in Remotely or Locally
How to join the main session of a remote computer
The mstsc /console
or mstsc /admin
command in newer Windows versions helps you join the main session of a remote computer. This is great for certain apps or admin tasks that need the main session.
Here’s how to do it:
- Open the command prompt.
- Type this command and press Enter:
mstsc /admin /v:yourRemoteComputer
Change “yourRemoteComputer” to the computer’s name or IP you want to connect to.
This starts a session to the remote computer’s main session. But be careful, because this session might already be in use, and you don’t want to interrupt someone’s work.
Linked issue: Windows 11 Remote Desktop “An authentication error has occurred”
How to begin and end a remote desktop session
Handling Remote Desktop sessions is key for remote system care. The mstsc
command starts a session. To end it, just close the Remote Desktop window. Or, for more control, use command line ways to finish it.
The logoff
command ends a session. You need the session ID, which you find by typing query session
.
logoff SessionID
Useful resource: How to Install Telnet via CMD or PowerShell in Windows 11
Using a RDP file for remote desktop
.rdp files are Microsoft Remote Desktop config files that save settings for sessions. They’re handy for connecting to a computer with specific settings without entering them each time.
Here’s how to make a .rdp file:
- Open Remote Desktop Connection by typing mstsc in the command prompt or search bar and press Enter.
- In the window, put the remote computer’s name or IP in the “Computer” field.
- Click “Show Options” for more settings, like your username, display options, and more.
- After setting things up, click “Save As” under Connection settings.
- Save the .rdp file where you want, with a name you choose.
To use the .rdp file, type this command, swapping “C:\file.rdp” with your .rdp file’s location and name:
mstsc C:\file.rdp
This opens a Remote Desktop session with your saved settings. If you saved your login info in the .rdp file, it’ll log you in automatically; otherwise, you’ll need to type your password.
Turning on remote access in Windows 11
Before making a remote connection, the computer you want to connect to must have Remote Desktop turned on. While you can easily do this in Windows 11 settings, you can also use the command line with PowerShell for more direct control.
To turn on Remote Desktop with PowerShell, first open PowerShell as an admin. Type “PowerShell” in the Windows search bar, right-click the Windows PowerShell app, and choose “Run as administrator.”
Then, enable Remote Desktop with this command:
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0
How to run commands on a remote system
For system management, sometimes you need to run commands on another computer. Windows has a tool called PsExec
in the Sysinternals suite for this. After installing PsExec
, you can use it to run commands remotely like this:
psexec \\remoteComputer command
Replace “remoteComputer” with the remote computer’s name, and “command” with what you want to do.
To sum up
We’ve covered how to use the command prompt for Remote Desktop stuff in Windows 11. From basic connections to more detailed tasks like joining a computer’s main session, using the command line gives you lots of flexibility and efficiency for managing remote connections (especially useful if you’re a network admin).
Command lines are great for when you need to automate things, do lots of tasks at once, or work on computers without using the graphical interface. .rdp files help save session settings for later, and tools like PsExec
and the mstsc /admin
command give you more control over remote computers.
But, always use these commands wisely and correctly to avoid messing up someone else’s work or making the system less secure. Make sure your RDP connections are safe and only let trusted people access them.
Приветствую. Иногда возникают задачи когда нужно что-либо сделать на удаленном компьютере, при этом либо нет возможности подключиться по RDP, например, если вдруг сервер сильно загружен, и ему не хватит ресурсов для запуска терминальной сессии (да да, у меня такое встречалось, не сказать что часто, но бывало ). Либо из командной строки задачу сделать быстрее. Ну или еще как вариант, если нужно что то сделать скрытно, в том случае если пользователь в момент когда это нужно сделать работает за компьютером. Пользователям Linux с этим гораздо проще, у них есть ssh. Но и в Windows есть возможность подключаться, с позволения сказать, в командную строку.
В общем и целом на помощь к нам приходят утилиты SysInternals, а именно – pstools, а еще конкретнее – psexec из этого набора утилит. Скачать это добро можно здесь.
После того как скачали, нужно эти утилиты разархивировать куда-нибудь. Я обычно на диске C: создаю папку ps, что бы удобнее было добираться до утилит. Установки они не требуют. Для того что бы подключиться к удаленному компьютеру в командной строке набираем:
c:\ps\PsExec.exe \\192.168.1.114 -u domain\user -p password cmd
За место cmd можно например запустить какой-нибудь батник или другую команду.
Видео по теме:

You can connect remotely to computer.
Image Credit:
golubovy/iStock/GettyImages
If you’re going to be away from your home computer, but you’ll need to access it to perform a task or pull up a file, the remote desktop connection feature on Windows is the tool you need. There are some limitations. You need to have configured remote desktop on the PC previously, and it has to be switched on and not hibernating or sleeping.
With the right preparations, you can go directly to the computer you need to use from a distance. Although there are other approaches, you can easily connect to another computer using Command Prompt on the machine you’re currently on.
Set Up Remote Desktop Connection
Before you can connect to another PC via Command Prompt, you need to set up the feature on the computer you want to connect to. To do this on Windows 10, you need a Pro or business version of Windows (rather than Home). Click the Windows button to open the Start menu, then go to Settings by clicking the gear icon. Choose System, scroll down to Remote Desktop on the left, and then switch on Enable Remote Desktop.
Make a note of the name written under «How to connect to this PC.» You may need it later.
You can also do this on older versions of Windows, such as Windows 8. Open the Control Panel and go to System and Security. Under System, click Allow Remote Access to bring up the System Properties dialogue. Go to the Remote tab and select the radio button beside Allow remote connections to this computer.
Specify Users Who Can Access
When you set up remote access, only users with admin privileges can access the machine remotely by default. However, if you want others to be able to access the computer, you can give them access. Click where it says Select users that can remotely access this PC from the User Accounts section at the bottom, and then click Add on the window that appears. In the new window, enter the username (or usernames) for the accounts you want to have access and then click OK.
Use CMD to Access Another Computer
After you set up remote access, you can use another computer’s Command Prompt program to connect to your computer. Press the Windows key+r together to bring up Run, type «cmd» in the field, and press Enter. The command for the Remote Desktop connection app is «mstsc,» which you use to launch the program. You are then prompted for the computer’s name and your username.
You can use additional terms at the end of the command to access the computer directly through Command Prompt. Type «mstsc /console /v:computername» into Command Prompt, with the specific computer name you wrote down earlier in place of «computername.» This entry takes you straight to the login screen for your remote computer. After you log on, you can use the remote machine as if it is the one you’re sitting infront of.
You can also use the public IP address of your computer in place of the computer name to complete your connection. If you don’t know the public IP, you can search «what’s my IP» in Google, and it returns the answer immediately. You should set up a static (rather than dynamic) IP for your machine if you connect to it regularly; otherwise, the IP will change.
Additional Options for Command Prompt
You can also specify more when you open the remote desktop through Command Prompt. For example, add «/f» to the end of your command to open the desktop in full screen, or use «/w:» and «/h:» with values in place of «» and «» to open in a custom size. You can list all the available parameters using «/?» after your command.