|
发表于 2023-6-18 11:36:29
|
显示全部楼层
您好!要使用C#程序连接RDP及RemoteApp需要使用`MSTSCLib`库。
- using System;
- using System.Windows.Forms;
- using MSTSCLib;
- namespace RDP_Connection
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void bConnect_Click(object sender, EventArgs e)
- {
- try
- {
- // 配置RDP控件参数
- axRDPControl.DesktopHeight = 1024;
- axRDPControl.DesktopWidth = 1280;
- axRDPControl.AdvancedSettings7.SmartSizing = true;
- axRDPControl.ColorDepth = 32;
- // 设置RDP文件信息
- IMsTscNonScriptable secured = (IMsTscNonScriptable)axRDPControl.GetOcx();
- secured.ClearTextPassword = "mypassword"; // RDP密码
- axRDPControl.Server = "myserver.com"; // RDP server地址
- axRDPControl.UserName = "myusername"; // RDP登录用户名
- axRDPControl.Domain = null; // RDP登录域
- // 使用上面的rdp配置信息链接RDP
- axRDPControl.Connect();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void bDisconnect_Click(object sender, EventArgs e)
- {
- axRDPControl.Disconnect(); // 断开RDP连接
- }
- }
- }
复制代码
对于RemoteApp连接,建议将其部署在Web服务器中并运行。以下是一个示例:
- private void button1_Click(object sender, EventArgs e)
- {
- MsRdpClient8NotSafeForScripting client = new MsRdpClient8NotSafeForScripting();
- client.Server = "myserver.com";
- client.AdvancedSettings7.EnableCredSspSupport = true;
- client.AdvancedSettings7.AuthenticationLevel = 2;
- client.UserName = "myusername";
- client.SecuredSettings.FullScreen = false;
- //RemoteApp连接
- IMsTscNonScriptable secured = (IMsTscNonScriptable)client.GetOcx();
- secured.ClearTextPassword = "mypassword"; // RemoteApp登录密码
- client.AdvancedSettings8.RDPPort = 3389; // 连接端口,默认为3389
- client.AdvancedSettings8.RemoteProgram2 = "rdpinit.exe"; // RemoteApp程序名
- client.AdvancedSettings8.RemoteApplicationMode = true; // 启用RemoteApp模式
- client.Connect();
- }
复制代码
希望这些代码能够帮助您连接RDP和RemoteApp。谢谢!
求最佳答案 |
|