How to use Remote Desktop Connect for Windows XP to Run Commands Remotely

It is very useful to be able to run a command on a remote computer. I use it to synchronise files between my local PC and a remote server that I have. It allows me to run any command I like, which in my case is a batch file of commands that copy some files from one PC to another and then process them a little. Linux guys have had all this stuff for years, but getting it to work on PCs has never been that easy.

How it works

If you've used Remote Desktop to control another PC remotely, then you already will be familiar with part of it. What we are going to do is wrap up the Remote Desktop Connection into a single batch file that we can put behind an icon. Then, all we need to do is to click this icon and the remote desktop will be fired up, some commands will run on the remote desktop, and then the remote will log off and shut down.

What is required:

The local PC batch file

This is very simple, and just contains one line:

mstsc c:\path\to\file\my-rdp-file.rdp

MSTSC is the name of Remote Desktop Connection when called from the command line (DOS). Just pass it the full path to your rdp file, which we will set up in the next step.

The .rdp file configuration and parameters

RDP files are a bit complicated, but you can use the MSTSC program to make a barebones one for you, and then modify it using notepad. To do this:

  1. From the command line, type MSTSC to start the Remote Desktop Connection.
  2. Click "Options >>>" to see the full set of options .
  3. In the Computer field, enter the IP address of the remote computer.
  4. Enter your username and password for the remote computer. Obviously you must have a valid login for the remote PC.
  5. Clear the Domain field, as no domain is needed when an IP address is supplied.
  6. On the "Local Resources" tab, if you click the "Disk Drives" checkbox, you will be able to access the local PC's disks from the remote PC, which could be useful if you want to copy files between the two.
  7. On the programs tab, enter the directory that you want your remote batch file to run in, and also the name of the batch file, such as my-batchfile.bat
  8. Go back to the "General" tab and click "Save As..." to save this configuration as an .rdp file.

Once you have saved the RDP file, you can edit it in notepad or any text editor. The format is a bit weird, but basically each line looks like this:

parameter name : parameter type : value

The parameter type is "i" for an integer value, "s" for a string, and "b" for a binary value.

Here is an example file:

screen mode id:i:2
desktopwidth:i:1152
desktopheight:i:864
session bpp:i:16
winposstr:s:0,1,0,0,800,600
full address:s:80.90.100.110
compression:i:1
keyboardhook:i:2
audiomode:i:0
redirectdrives:i:1
redirectprinters:i:0
redirectcomports:i:0
redirectsmartcards:i:1
displayconnectionbar:i:1
autoreconnection enabled:i:1
username:s:my-user-name
domain:s:
password 51:b:8CCF6377E3C14000000DEC7298F68D473CA7019D9A7B89F1C11F0D98BE70
disable wallpaper:i:1
disable full window drag:i:0
disable menu anims:i:0
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1
alternate shell:s:my-remote-commands.bat
shell working directory:s:d:\windows

You can just edit any of the values you want once you have the basic rdp file saved somewhere.

The remote batch file

You can put any DOS commands you like in the remote batch file. The whole lot will be executed, and then when the batch file ends, the remote computer will log off automatically. Easy eh?

I use ROBOCOPY to synchronise lots of files from the local PC to the remote one. Robocopy is a free tool you can find on Microsoft's website. From the remote PC, the local PC's disks are visible as \\tsclient\c\my-directory

Conclusion

So that's it. You now know how to run commands remotely on another PC over the internet or over your LAN, using all free tools that you probably have on your Windows XP machine already.