与MSTSCLib的远程桌面连接

时间:2011-11-08 21:35:39

标签: c# .net remote-desktop

我正在尝试使用C#.NET编写远程桌面应用程序。

我按照一些示例(下面列出)创建了一个Windows窗体,添加了对MSTSLib的引用,将Microsoft终端服务控件添加到窗体并编写了以下行为:

namespace RDConnector
{
    public partial class Form1 : Form
    {    
        const string server = "55.55.55.555";
        const string userNameBase = "username";
        const string passwordBase = "password";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                rdClient.Server = server;
                rdClient.UserName = userNameBase;    

                /*IMsTscNonScriptable secured = (IMsTscNonScriptable)rdClient.GetOcx();
                secured.ClearTextPassword = passwordBase;*/

                rdClient.AdvancedSettings8.DisplayConnectionBar = true;
                rdClient.AdvancedSettings8.ClearTextPassword = passwordBase;
                rdClient.AdvancedSettings8.EncryptionEnabled = -1;                 

                //// Start connection
                rdClient.Connect();
                MessageBox.Show("Connection Status + " + rdClient.Connected.ToString());

            }
            catch (Exception Ex)
            {
                MessageBox.Show("Exception ocurred: " + Ex.Message);
            }
        }
    }
}

但是,它无效,调用rdClient.Connect()后的连接状态为2(调用前为0),但没有任何反应。我也运行了示例1,它不起作用。

我正在使用Windows 7 - 64位和Visual Studio C#Express。 Visual Express Edition没有X64编译器,可能是与此相关的问题吗?

我真的很感谢你的帮助。

示例:

  1. http://www.codeproject.com/KB/cs/RemoteDesktop_CSharpNET.aspx

  2. Running COM component controls on multiple threads

1 个答案:

答案 0 :(得分:1)

我终于找到了问题。如果要选择COM组件,只需选择" Microsoft RDP客户端控件 - 版本x"。我选择适合我的8版本。

相关问题