远程桌面RDP C#使用Microsoft RDP Client Control 演示 | 您所在的位置:网站首页 › 利用radmin实现远程控制 › 远程桌面RDP C#使用Microsoft RDP Client Control 演示 |
系统环境: 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例子下载 |
CopyRight 2018-2019 实验室设备网 版权所有 |