Search code examples
c#remote-desktopterminal-services

Terminal Services -: Value does not fall within the expected range


Test driving a remote desktop feature in an app but keep getting a weird error with the server name I'm putting in.

Code:

        rdp.Server = txtServer.Text;
        rdp.UserName = txtUser.Text;
        IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
        secured.ClearTextPassword = txtPass.Text;
        rdp.Connect();

Keep getting the error:

An unhandled exception of type 'System.ArgumentException' occurred in AxInterop.MSTSCLib.dll

Additional information: Value does not fall within the expected range.

On line:

 rdp.Server = txtServer.Text;

txtServer.Text is being input as (but with a real address):

123.456.789.10:1234

Anybody else had this issue?

EDIT

The issue is with the port in the address, how can I get around this?


Solution

  • There should be an .AdvancedSettings.RDPPort property where you can set the port. Look at this CodeProject article, specifically page 2 of the comments.