Configuring Windows Remote Desktop from the command line

by [Published on 28 July 2009 / Last Updated on 28 July 2009]

How to use Windows Remote Desktop (mstsc.exe) from the command line to connect to remote servers from saved shortcuts or with custom options.

Introduction

If you are interested in using Windows Remote Desktop from the command line, likely you already know what it does but you may not have realized all that you can do with it. Windows Remote Desktop allows you to remotely control just about any windows PC or Server. 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 the Windows Operating System whether it is XP, Vista, or Windows 7 (but you must authorize remote desktop to that computer). On the desktop side, that connection to the PC is limited to a single connection where you remote control the console. However, on the server side, in say Windows 2003 or 2008, you can enable multiple users to connect to the server with Terminal Services.

However, no matter whether you are using a desktop or server OS, the client piece of software is the same – the Remote Desktop Connection or Remote Desktop Client, as I like to call it. The executable for the Remote Desktop Connection is called mstsc.exe and it’s located in %systemroot%/system32/mstsc.exe.

Let us learn all that you can do with mstsc.exe…

Running Windows remote Desktop Connection from the CLI

In Chris Sander’s WindowsNetworking.com Admin Tip - Using the Remote Desktop Client from the Command Prompt – he covers the quick command line how-to of Windows Remote Desktop. As Chris points out, the basic command syntax for mstsc.exe is:

mstsc.exe {ConnectionFile | /v:ServerName[:Port]} [/console] [/f] [/w:Width/h:Height]

However, if in Vista, you run mstsc /?, you will see that there are more options for it:


Figure 1:  Remote Desktop Connection Usage Help Screen

On most computers I walk up to and use, the remote desktop connection is not easily locatable in the Start Menu. Because of this, I have gotten used to starting Remote Desktop by going to Start -> Run and then just typing mstsc and pressing Enter.

This way I do not spend any time navigating the Programs menu.

Common reasons to run mstsc from the CLI

I love Remote Desktop because from my laptop or desktop system, I can connect to any of my PCs or servers in my infrastructure. It is very “empowering”.

I often need to use the command line options. One common thing to do is to save a RDP File, which is a saved configuration file for a particular RDP connection – or really a particular server or PC that you commonly connect to. Of course, you could even have multiple RDP files for the same server or PC if you want to have multiple saved configuration files.

These “.rdp” files are just simple text files that you can create or edit with notepad. Here is a look at one:


Figure 2:  RDP file opened in notepad

While you can do this with notepad, the most common way to edit a .RDP file is to use the GUI Remote Desktop client because it offers options to Open, Save, and Save as connection files, like this:


Figure 3:  Opening and Saving RDP Connection Settings

I can also edit a particular file using the GUI but initiate it from the command line with the /edit option for mstsc, like this:

mstsc /edit test.rdp

Some common reasons that I would save RDP files for later use are:

  • Have save connections to multiple servers and put those saved settings on my desktop or in the folder in the Start menu, like this:


Figure 4: Creating multiple RDP server connections in the Start Manu

  • Have multiple versions of the same connection – maybe I connect to a virtual desktop using VDI and I have one icon that creates a full screen RDP connection and one that creates an 800x600 resolution connection
  • Perhaps I have one RDP file that connects to a server and another RDP file that connects to a server and runs an application (which can be specified in the .rdp file)

Creating a Desktop Shortcut to run Remote Desktop

Let us say that you wanted to create a desktop shortcut to connect to a particular server. You could either use the base set of command line options or you could use those options and a .rdp connection file.

Either way, you need to be able to enter the full command line into the desktop shortcut creation wizard.

Let us say you want to create a desktop shortcut to:

  • Connect to server “exchange”
  • Connect to the console of that server
  • Create an 800x600 window

To do this you would run:

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

And to create a desktop shortcut, you would enter this into the create shortcut location, like this:


Figure 5: Creating a desktop shortcut with RDP

However, if those basic options are not enough, you need to use a .rdp connection file.

To do this, just run mstsc.exe, go in and customize your connection all that you want. Add sound, customize the bandwidth, set an application to be run, tweak the performance, connect local devices & resources like printers and the clipboard. When you are done, just click the Save as button on the General tab under connection settings. When you save it, give it a name like fileserver. Make sure that you know what folder your RDP file was saved in. I also recommend testing your connection here to ensure that it works as expected.

Once saved, you can close out the Remote Desktop Connection window and then go to create your desktop shortcut. When you enter the desktop shortcut location, you will enter the connection file after msctsc.exe. Make sure that you enter the full path to the .rdp file. The .rdp file needs to be in your path, or your desktop shortcut and .rdp file should be in the same folder. Thus, it would look something like:

Mstsc.exe c:\users\david\documents\exchange.rdp

OR, if you are all going to run mstsc with a connection file, you do not need to create a desktop shortcut at all. All you have to do is to save the RDP connection settings file then run it. The file itself, when run, is associated with mstsc.exe so it will be run and your connection will automatically initiate to the server specified in the connection file.

One final tip – if you want to change the defaults that mstsc uses to connect when you run it without any customizations, you can edit the Default.rdp file in your home documents folder.

Summary

Windows Remote Desktop is an amazingly powerful tool and it is hard to imagine life without it. While it is easy to connect to a server using the RDP GUI, once you use RDP a few times, you will want to do much more with it. Using command line options with mstsc.exe and creating desktop shortcuts to connect to particular servers is the next step that you need to make.

You can find more information about Remote Desktop at the following links

Featured Links