In this article we 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.
Windows Remote Desktop allows you to remotely control almost all Windows PCs or Server Servers. You can perform remote control from PC to PC, server to server, PC to server, or server to PC. The RDP server component is built into the Windows XP, Vista, or Windows 7 operating systems (however, you must authorize the remote desktop for that computer). On the desktop side of the connection to the PC will be 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.
However, whether you are using a desktop operating system or a server, the client software is exactly the same – Remote Desktop Connection or Remote Desktop Client. The executable file for the software is called mstsc.exe and has a path of %systemroot%/system32/mstsc.exe.
Here we will learn about what you can do with mstsc.exe…
Run the Windows Remote Desktop Connection from the CLI
In using the Remote Desktop Client from the command prompt, you can use the basic command syntax for mstsc.exe as follows:
However, in Vista, run mstsc /?, For some other options:
On most computers we use, the use of remote desktop connections is not easily defined in the Start Menu. So for simplicity you should use Start -> Run, then type mstsc and press Enter.
Some reasons to run mstsc from CLI
Surely you would prefer Remote Desktop because from your laptop or desktop system, you can connect to any PC or server in your infrastructure. This method actually creates a lot of convenience.
If you frequently use command line options. One thing you’ll usually have to do is save an RDP File, which is a configuration file that has been saved for an RDP connection – or the server, PC you normally connect to. Of course, there may be multiple RDP files for the same server or PC if you want to have multiple configuration files saved.
The “.rdp” files are simply text files that you can create or edit with notepad. Here is an example of the contents of the .rdp file:
You can work inside notepad, but the most commonly used way to edit a .RDP file is to use the GUI Remote Desktop client as it offers much more convenient Open, Save, and Save as for connection files:
You can also edit a file using the GUI but launch it from the command line with the /edit option for mstsc as follows:
mstsc /edit test.rdp
Several reasons for saving RDP files for future use:
- You can save connections to multiple servers and use the settings saved on your desktop or in a folder in the Start menu, as shown below:
- In case there are multiple versions of the same connection – you can connect to a virtual desktop with VDI, which can use an icon to make a full screen RDP connection or with 800×600 resolution.
- It may be necessary to have 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 certain server. You can use the basic command line options or you can use that option and the .rdp file.
However, no matter which way you use it, you also need to enter the full command line in the desktop shortcut wizard.
Let’s go create a desktop shortcut:
- Connect to server “exchange”.
- Connect to the console of that server.
- Create an 800×600 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 following command into create shortcut location, as shown below:
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 desired. Such as adding sounds, adjusting bandwidth, setting up running applications, tuning performance, connecting local devices and resources like printers. When all that work is done, just click the Save as button on the General tab. Once saved, name the file fileserver. Make sure you know the directory where the RDP file is stored. 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 a desktop shortcut. When entering the location of the desktop shortcut, you need to enter the connection file after msctsc.exe. Be sure to enter the full path for the .rdp file. The .rdp file needs to specify the path or desktop shortcut and the .rdp file must be in the same directory. Thus, the syntax for the statement is as follows:
If you run mstsc with a linked file, then you do not need to create a desktop shortcut. All you have to do now is save the RDP connection setup file and then run this file. This file, when run, will connect to mstsc.exe so it will automatically initiate a connection to the specified server within the connection file.
One last tip – if you want to change the default settings that mstsc uses to connect to when you want to run the file without any modifications, edit the Default.rdp file in your home directory.
Windows Remote Desktop is a very powerful analytical tool and it’s hard to imagine what would happen without this tool. In addition to creating an easy connection to the server using the RDP GUI, one asserts that once you have used RDP a few times, you will want to use it a lot more. Using the command line options with mstsc.exe and creating shortcut desktops to connect to certain servers is the next step you need to take.