RDP change port number

21 May

Here’s the brain dump on port changes:

===================================== Serverside Port Change:
This is documented in the following article –
How to Change Terminal Server’s Listening Port (Q187623) http://support.microsoft.com?id=kb;en-us;Q187623
Basically, you need to change the value of the following registry entry: HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
Please note the following – (1) The port is normally displayed as a hex number; the default 3389 shows up as 0d3d. Make sure you watch whether it is in hex or decimal mode when entering a new port! if you change the port to 2028 but are in hex mode, that’s actually equivalent to 8232 decimal! (2) You will need to restart the server for the changes to take effect.

===================================== Clientside Port Change
This has to be handled on a per-connection basis.
A – With the Full TS Client:
A.1 – Command Line
If running from the commandline, just add a colon and the new decimal port number to the IP address/servername. For example, if the server is “Hydra” and the new port number is 4000, you would run

    mstsc /v:Hydra:4000

A.2 – In The GUI
In the GUI, do the same – add :<portnumber> to the server name, so instead of just typing Hydra, type Hydra:4000.
A.3 – In an RDP file
If you save settings to an RDP file, you can keep the port number in there. There are two ways to do this. Either
+ find the “full address” parameter, which should like this

    full address:s:Hydra

and change it to

    full address:s:Hydra:4000

OR + add a new line for “port” to the file, like this:


B – With the Web Client
There’s only one way to do this. You need to set a value for AdvancedSettings2.RDPPort within the web page hosting the client. If the variable name representing the client is “MsRdpClient” this can be done like this anywhere in the page that is executed before the client’s Connect() method is called:

    MsRdpClient.AdvancedSettings2.RDPort = 4000

Note that the same technique works if you have the client embedded in an application, HTA, or running from a direct script.