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

2023-05-16

系统环境:

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例子下载
 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

远程桌面RDP C#使用Microsoft RDP Client Control 演示 的相关文章

随机推荐