C#使用RDP的远程桌面应用程序。 如何生成证书?

我有一些问题,使用MSTSCLib从1台PC连接到另一台PC。

它与服务器一起使用,但不与普通的工作站一起工作……

private void btn_connect_Click(object sender, EventArgs e) { try { rdp_control.Server = tbx_servername.Text; rdp_control.Connect(); tabPage1.Text = "Connected"; } catch (Exception exp) { MessageBox.Show(exp.ToString()); } } private void btn_disconnect_Click(object sender, EventArgs e) { if (rdp_control.Connected.ToString() == "1") { rdp_control.Disconnect(); } } 

客户端和服务器应用程序都在同一NAT下的同一网络中。 问题是证书,……我需要找到一种方法来包含证书。 使用Windows上的普通远程桌面,您会看到一个MessageBox,其中包含以下问题:“您是否要使用此证书…. blablabla”但是这不是c#中的RDPfunction

有任何想法吗? 谢谢BR

以下代码显示了一个简单的RDP客户端和服务器。

RDP服务器

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using RDPCOMAPILib; using AxMSTSCLib; using System.Runtime.InteropServices; namespace TCP_to_RDP_Converter { public partial class Form1 : Form { public static RDPSession currentSession = null; public static void createSession() { currentSession = new RDPSession(); } public static void Connect(RDPSession session) { session.OnAttendeeConnected += Incoming; session.Open(); } public static void Disconnect(RDPSession session) { session.Close(); } public static string getConnectionString(RDPSession session, String authString, string group, string password, int clientLimit) { IRDPSRAPIInvitation invitation = session.Invitations.CreateInvitation (authString, group, password, clientLimit); return invitation.ConnectionString; } private static void Incoming(object Guest) { IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest; MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE; } ///  /// Handle the form items ///  public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { createSession(); Connect(currentSession); textConnectionString.Text = getConnectionString(currentSession, "Test","Group","",5); } private void button2_Click(object sender, EventArgs e) { Disconnect(currentSession); } } } 

为了使用RDP通信库,您需要添加rdpcompapi和Microsoft Windows终端服务,形成COM引用。

RDP客户端

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using RDPCOMAPILib; using AxRDPCOMAPILib; namespace Simple_RDP_Client { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static void Connect(string invitation, AxRDPViewer display, string userName, string password) { display.Connect(invitation, userName, password); } public static void disconnect(AxRDPViewer display) { display.Disconnect(); } private void button1_Click(object sender, EventArgs e) { try { Connect(textConnectionString.Text, this.axRDPViewer, "", ""); } catch (Exception) { MessageBox.Show("Unable to connect to the Server"); } } } } 

您可以通过将RDP查看器类组件导入主窗体来添加对AxRDPCOMAPILib的引用。

完整项目可以从这里下载[下载]: http : //sandaruwmp.blogspot.com/2014/05/remote-desktop-application-with-rdp.html

用这个….

 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MSTSCLib; namespace RemoteTool { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MSTerminalServiceControl1.Server = textBox1.Text; MSTerminalServiceControl1.UserName = textBox2.Text; IMsTscNonScriptable secured = (IMsTscNonScriptable)MSTerminalServiceControl1.GetOcx(); secured.ClearTextPassword = textBox3.Text; MSTerminalServiceControl1.Connect(); } private void button2_Click(object sender, EventArgs e) { MSTerminalServiceControl1.Disconnect(); } } } 

在此处输入图像描述