Configure Windows Remote Desktop from the command line

In this article, I will show you how to use Windows Remote Desktop (mstsc.exe) from the command line to connect to remote servers from saved shortcuts or other options.
In this article, I will show you how to use Windows Remote Desktop (mstsc.exe) from the command line to connect to remote servers from saved shortcuts or other options.

Introduce

Windows Remote Desktop allows you to remotely control almost all Windows computers or Server servers. You can perform remote control from PC to PC, server to server, PC to server, or server to PC. The server component of RDP is built into Windows XP, Vista, or Windows 7 operating systems (however, you must authorize the remote workstation for that computer). On the desktop side, the connection to the PC is limited, but on the server side (such as Windows 2003 or 2008) you can allow multiple users to connect to the server using Terminal Services.

Even if you are using a desktop or server operating system, the client software is the same - Remote Desktop Connection or Remote Desktop Client. The executable file for the software is called mstsc.exe and has the path % systemroot% / system32 / mstsc.exe .

Here we will learn about what you can do with mstsc.exe .

Run Windows remote Desktop Connection from CLI

In using the Remote Desktop Client from the command prompt, you can use the basic command syntax for mstsc.exe as follows:

/ v: ServerName [: Port]} [/ console] [/ f] [/ w: Width / h: Height]

However, in Vista, please run mstsc /? , to get some more options:

Configure Windows Remote Desktop from the command line Picture 1Configure Windows Remote Desktop from the command line Picture 1
Figure 1: Monitor help for remote desktop connection

On most computers we use, the use of remote desktop connection is not easy to identify in the Start Menu. So to simplify it, you should use Start -> Run , then type mstsc and press Enter.

Some reasons should run mstsc from CLI

Sure you will like Remote Desktop because from a laptop or desktop system, you can connect to any of your PCs or servers in the infrastructure. This method really makes a lot of convenience.

If regularly use the command line options. One thing you will often have to do is save a RDP File , which is a configuration file that has been saved for an RDP connection - or the server or PC you usually connect to. Obviously, there may be multiple RDP files for the same server or PC if you want to have multiple saved configuration files.

The '.rdp' files are simply text files that you can create or edit with notepad. Here is an example of the content of the file '.rdp':

Configure Windows Remote Desktop from the command line Picture 2Configure Windows Remote Desktop from the command line Picture 2
Figure 2: The RDP file is opened in notepad

You can work inside notepad, but the most commonly used way to edit a .RDP file is to use the GUI Remote Desktop client because it provides more convenient Open, Save, and Save as options. for connection files:

Configure Windows Remote Desktop from the command line Picture 3Configure Windows Remote Desktop from the command line Picture 3
Figure 3: Opening and saving RDP connection settings

You can also edit a file using the GUI but launch it from the command line using the / edit option for mstsc as follows:

mstsc / edit test.rdp

Some reasons for saving RDP files for later use:

  1. You can save connections to multiple servers and use the settings saved on your desktop or in a certain folder in the Start menu , see illustration below:

Configure Windows Remote Desktop from the command line Picture 4Configure Windows Remote Desktop from the command line Picture 4
Figure 4: Create multiple RDP server connections in Start Manu

  1. In the case of multiple versions of the same connection - you can connect to a virtual desktop using VDI, you can use an icon to create a full-screen RDP connection or with 800x600 resolution.
  2. You may need an RDP file to connect to the server, another RDP file to connect to the server and run an application (all of which can be specified in the .rdp file).

Create Desktop Shortcut to run Remote Desktop

If you want to create a desktop shortcut to connect to a server. You can use the basic script of command line options or you can use those options and the .rdp connection file.

However, no matter how you use it, you need to enter the full command line in the desktop shortcut creation wizard.
Let's create a desktop shortcut:

  1. Connect to 'exchange' server
  2. Connect to the console of that server
  3. Create a 800x600 window

To do that, you need to run the command:

mstsc.exe / v: exchange / admin / w: 800 / h: 600

And to create a desktop shortcut, you need to enter the above command into create shortcut location , as illustrated below:

Configure Windows Remote Desktop from the command line Picture 5Configure Windows Remote Desktop from the command line Picture 5
Figure 5: Creating a shortcut desktop with RDP

If these basic options are not enough, you can use the .rdp file .

To do this, you need to run mstsc.exe , then customize your connection as you like. Such as adding audio, adjusting bandwidth, setting applications to be run, adjusting performance, connecting internal devices and resources such as printers. When you have done all these tasks, simply click the Save as button on the General tab. After saving, name the file as fileserver . Make sure you know the directory with this RDP file saved. You should also check your connection here to make sure it works as expected.

Once saved, you can close the Remote Desktop Connection window, create your desktop shortcut. When entering the desktop shortcut location, you need to enter the connection file after msctsc.exe. Be sure to enter the full instructions for the .rdp file. The .rdp file needs to specify the path or the desktop shortcut and the .rdp file need to be in the same directory. Therefore, the syntax of the statement will be as follows:

Mstsc.exe c: usersdaviddocumentsexchange.rdp

If you run mstsc with a connection file, then you don't need to create a desktop shortcut. All you have to do now is save the RDP connection settings file and then run this file. The file itself, when run, will connect to mstsc.exe so it will automatically initiate a connection to the specified server within the connection file.

One final tip - if you want to change the default settings that mstsc uses to connect when you want to run the file without any adjustments, edit the Default.rdp file in the home directory.

Conclude

Windows Remote Desktop is a powerful analysis tool and it's hard to imagine what would happen without this tool. In addition to making an easy connection to the server using RDP GUI, one asserts that once you've used RDP a few times, you'll want to use it more. Using command line options with mstsc.exe and creating desktop shortcuts to connect to certain servers is the next step you need to take.

David Davis

4 ★ | 13 Vote