远程桌面RDP C#使用Microsoft RDP Client Control 演示

  • Post author:
  • Post category:其他


系统环境:

window10

visual studio 2019

.net framework 4.0

Microsoft RDP Client Control (redistributable) – version 7

步骤:

1、vs2019 新建一windows from桌面应用项目RemoteDesktopDemo,.net framework 4.0(低于此版本会出程序集不能加载错误)

2、添加Microsoft RDP Client Control (redistributable) – version 7控件

工具箱空白处鼠标右键->选择项

在com组件处选择Microsoft RDP Client Control  – version 7

确定后,工具箱上控件就可以使用了。

版本要求:

3、在Form1窗体上使用此控件,并添加服务器、用户名、密码等控件如图

单击Connect代码

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                rdp.Server = txtServer.Text;
                rdp.UserName = txtUserName.Text;

                IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
                secured.ClearTextPassword = txtPassword.Text;
                //special port
                //rdp.AdvancedSettings2.RDPPort = 3389;
                //share local drivers
                rdp.AdvancedSettings2.RedirectDrives = chbShareLocalDrivers.Checked;
               
               

                rdp.Connect();
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + txtServer.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

单击disConnect代码

        private void btnDisconnect_Click(object sender, EventArgs e)
        {
            try
            {
                // Check if connected before disconnecting
                if (rdp.Connected.ToString() == "1")
                    rdp.Disconnect();
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Error Disconnecting", "Error disconnecting from remote desktop " + txtServer.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

选中ShareLocalDrivers时,共享本地磁盘

4、运行结果

文章开头有本示例源码下载 ,或此处

RemoteDesktopDemo例子下载



版权声明:本文为zhujisoft原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。