How to Start Remote Desktop Connection (mstsc) using Command Line

Remote Desktop Connection MSTSC Through Command LineRemote Desktop Connection MSTSC Through Command Line

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.

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.

rdc search
Search for RDC

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.

RDC tool with IP address

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 in Run

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
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.

ip and port
mstsc with IP address and port number

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.

computer name
RDC with computer name

Launch RDC in full-screen mode

You can also launch the RDC connection in full-screen mode. Here is how:

mstsc /f
RDC in full-screen mode

These switches can be combined into a single command to execute an RDC connection to your preferences. Here is an example:

mstsc /f /v:
RDC full-screen with IP address and port number

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).
/adminTo establish a connection with administrative privileges.
/fView 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.
/publicRun the Remote Desktop Connection publicly (less secure).
/spanTo 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.
/restrictedAdminConnect 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.
/remoteGuardConnect your device to a remote device using the Remote Guard, which prevents sending credentials to a remote PC.
/promptTo prompt you to put in credentials to connect to the remote PC.
/shadow:The ID of the session that you want to connect to.
/controlGive control of the session when shadowing.
/noConsentPromptTo allow shadowing without user consent.
/migrateMigrate legacy connection files created with Client Connection Manager to new .rdp connection files.
/?To get help in the command prompt.
MSTSC commands and Switches

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
Check RDP status from Command Prompt

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" }
rdp is enabled
Check RDP status from PowerShell

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.

If you liked this post, Share it on:
Subhan Zafar is an established IT professional with interests in Windows and Server infrastructure testing and research, and is currently working with Itechtics as a research consultant. He has studied Electrical Engineering and is also certified by Huawei (HCNA & HCNP Routing and Switching).

Get Updates in Your Inbox

Sign up for the regular updates and be the first to know about the latest tech information

Talk to us now

Talk to us straight and get your questions answered right away

Tell Us About Your Project
Web Dev Service Contact Form (Popup)