rdpcomapilib error connection failed

krushil G Patel 0 Reputation points
2023-04-03T17:24:31.73+00:00

Client Form is Generating Connection String And i am trying to connect with Remote desktop which has windows10 and the desktop is connected with ethernet And It is Showing Connection Failed in Remote Dekstop library used rdpcomapilib Host Code :->

using RDPCOMAPILib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace ScreenSharingApp
{
    public partial class Host : Form
    {
        public Host()
        {
            InitializeComponent();
            x.OnError += X_OnError;
        }

        private void X_OnError(object ErrorInfo)
        {
            MessageBox.Show(ErrorInfo.ToString());
        }

        RDPSession x = new RDPSession();
        
        private void Incoming(Object Guest)
        {
            try
            {
                label2.Text = "Connecting Guest Please Wait...";
                IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;
                MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
                label2.Text = "Guest Connected";
            }
            catch(Exception ex)
            {
                label2.Text = "Error In Connecting -> " + ex.Message.ToString();
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                label2.Text = "Doeing Setup Please Wait....";
                x.OnAttendeeConnected += Incoming;
                x.Open();
                label2.Text = "Setup Completed Please Click Get Connection String";
            }
            catch(Exception ex)
            {
                label2.Text = "Error In Setup :-> " + ex.Message.ToString();
            }
        }
        
        private void button2_Click_1(object sender, EventArgs e)
        {
            try
            {
                label2.Text = "Geting Connection String Please Wait....";
                IRDPSRAPIInvitation invitation = x.Invitations.CreateInvitation("Trail", "MyGroup", "", 10);
                textBox1.Text = invitation.ConnectionString;
                label2.Text = "Connection String Genrated";

            }
            catch(Exception ex)
            {
                label2.Text = "Error In Geting Connection String :->" + ex.Message.ToString();
            }
            
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            try
            {
                label2.Text = "Closeing please Wait.....";
                x.Close();
                x = null;
                label2.Text = "Connection Closed";
            }
            catch(Exception ex)
            {
                label2.Text = "Error In Closeing :-> " + ex.Message.ToString();
            }
            
        }

        private void Host_Load(object sender, EventArgs e)
        {

        }
    }
}

Client_Viewer Code :->

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace ScreenSharingApp
{
    public partial class Client_Viewer : Form
    {
        public Client_Viewer()
        {
            InitializeComponent();
        }

        
        private void button1_Click(object sender, EventArgs e)
        {
            

            string invitaion = textBox1.Text.ToString();
            rdp.Connect(invitaion, "User1", "");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            rdp.Disconnect();
        }

        private void rdp_OnError(object sender, AxRDPCOMAPILib._IRDPSessionEvents_OnErrorEvent e)
        {
            MessageBox.Show(e.errorInfo.ToString());
            label2.Text = "SomeThing went Wrong :-> " + e.errorInfo.ToString();
        }

        private void rdp_OnAttendeeConnected(object sender, AxRDPCOMAPILib._IRDPSessionEvents_OnAttendeeConnectedEvent e)
        {
            MessageBox.Show("Connected",e.pAttendee.ToString(),MessageBoxButtons.OK);
            label2.Text = "Connected :-> " + e.pAttendee.ToString();
        }

        private void rdp_OnAttendeeDisconnected(object sender, AxRDPCOMAPILib._IRDPSessionEvents_OnAttendeeDisconnectedEvent e)
        {
            MessageBox.Show("Disconnected", e.pDisconnectInfo.ToString(), MessageBoxButtons.OK);
            label2.Text = "Disconnected :-> " + e.pDisconnectInfo.ToString();
        }

        private void rdp_OnConnectionAuthenticated(object sender, EventArgs e)
        {
            label2.Text = "Connectioh Authenticated";
        }

        private void rdp_OnConnectionEstablished(object sender, EventArgs e)
        {
            label2.Text = "Connection Established";
        }

        private void rdp_OnConnectionFailed(object sender, EventArgs e)
        {
            label2.Text = "Connection Failed";
        }

        private void rdp_OnConnectionTerminated(object sender, AxRDPCOMAPILib._IRDPSessionEvents_OnConnectionTerminatedEvent e)
        {
            label2.Text = "Connection Terminated";
        }
    }
}

Is This a Neting Problem And if Yes Than How can is solve this. Please Help me With This Thing

Remote Desktop
Remote Desktop
A Microsoft app that connects remotely to computers and to virtual apps and desktops.
4,628 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,114 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,421 Reputation points
    2023-04-04T15:59:21.5533333+00:00
    Hello there,
    
    In order to use the RDP communication library you need to add rdpcompapi and Microsoft windows terminal services, form the COM references
    
    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");
                }
            }
        }
    }
    
    Hope this resolves your Query !!
    
    --If the reply is helpful, please Upvote and Accept it as an answer--
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.