使用 MSTSCLib 进行远程桌面连接

发布于 2024-12-14 12:12:24 字数 1917 浏览 5 评论 0原文

我正在尝试使用 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. 在多个线程上运行 COM 组件控件

I'm trying to code a Remote Desktop Application using C# .NET.

I followed some examples (listed below) and created a Windows Form, added references to MSTSLib, added Microsoft Terminal Service Control to the Form and code the following behavior:

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);
            }
        }
    }
}

However, it isn't working, the Connection status after calling rdClient.Connect() is 2 (0 before calling it), but nothing happens. I also ran the Example 1 and it doesn't work.

I'm using Windows 7 - 64 bit and Visual Studio C# Express. Visual Express Edition doesn't have a X64 compiler, Could be the problem related with that?

I'll really appreciate your help.

Examples:

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

  2. Running COM component controls on multiple threads

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛时过境迁 2024-12-21 12:12:24

我终于发现问题了。当您想要选择 COM 组件时,只需选择“Microsoft RDP 客户端控件 - 版本 x”。我选择最适合我的 8 版本。

I found the problem at last. When you want to choose COM Components, just select "Microsoft RDP Client Control - version x". I choose the 8 version that works perfectly for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文