使用RDP的C#远程桌面应用程序.如何生成证书? [英] C# Remote desktop application using RDP. How to generate the certificate ?

查看:191
本文介绍了使用RDP的C#远程桌面应用程序.如何生成证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MSTSCLib从一台PC连接到另一台PC时遇到一些问题.

I have some problems to use the MSTSCLib to connect from 1 PC to another one.

它适用于服务器,但不适用于普通工作站...

It's working with Servers but not with normal Workstations...

    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上的普通远程桌面,您会看到一个消息框,其中带有以下问题:您是否要使用此证书.... blablabla",但这不是c#中的RDP函数提供的.

Both client and server applications are in the Same Network under the same NAT. Problem is the certificate,... I need to find a way to include the certificate. With the normal Remote Desktop from Windows, you see a MessageBox with the question:"Do you want to use this certificate.... blablabla" But this is not coming up with the RDP function in c#

有什么想法吗?谢谢B.R.

Any Ideas? Thanks B.R.

推荐答案

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

Following code shows a simple RDP client and server.

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;
        }

        /// <summary>
        /// Handle the form items
        /// </summary>
        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引用.

In order to use the RDP communication library you need to add rdpcompapi and Microsoft windows terminal services, form the COM references.

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的引用.

you can add reference to the AxRDPCOMAPILib by importing RDP viewer class component to the main form.

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

Full project can be downloaded from here [Download]:http://sandaruwmp.blogspot.com/2014/05/remote-desktop-application-with-rdp.html

这篇关于使用RDP的C#远程桌面应用程序.如何生成证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆