title: Creating a Remote Desktop Client Application without using Windows Forms (C#)
body: <p>I need to build a Remote Desktop Client application with C#, which establishes a connection to a remote Windows Server, and then programmatically starts some services to the remote PC.</p>
  
  <p>It's important that, when I logon, the Desktop Environment on the Server side exists, because the services I want to start make use of it, but on the client side I don't want any Windows Forms container, because I want to create these sessions dynamically.</p>
  
  <p>To understand the question better, imagine that i want to establish a Remote Desktop Connection, using a console application.
  The point is, in the client side I don't need any GUI, but the services on the Host side need the windows, mouse, internet explorer etc UI handles.</p>
  
  <p>So far I tried to use the MSTSClib to create an RdpClient as discribed <a href="http://codeproject.com/Articles/43705/Remote-Desktop-using-C-NET" rel="noreferrer">here</a>, but that didn't help, because it makes use of the AxHost, which is Windows Forms dependent.</p>
  
  <p>Any ideas on if that's possible, and how can I achieve that?</p>
  
  <p>UPDATE:</p>
  
  <p>Tried this:</p>
  
  <pre><code>using System;
  using AxMSTSCLib;
  using System.Threading;
  using System.Windows.Forms;
  
  namespace RDConsole
  {
      class Program
      {
          static void Main(string[] args)
          {
  
              var thread = new Thread(() =&gt;
                  {
                      var rdp = new AxMsRdpClient9NotSafeForScripting();
                      rdp.CreateControl();
                      rdp.OnConnecting += (s, e) =&gt; { Console.WriteLine("connecting"); };
                      rdp.Server = "xxx.xxx.xxx.xxx";
                      rdp.UserName = "Administrator";
                      rdp.AdvancedSettings9.AuthenticationLevel = 2;
                      rdp.AdvancedSettings9.ClearTextPassword = "xxxxxxxxxx";
                      rdp.Connect();
                      Console.ReadKey();
                  });
              thread.SetApartmentState(ApartmentState.STA);
              thread.IsBackground = true;
              thread.Start();
              Console.ReadKey();
          }
  
  
      }
  }
  </code></pre>
  
  <p>but i get a null reference exception</p>
  
  <pre><code>"Object reference not set to an instance of an object.
  </code></pre>