title: Accessing Remote Desktop
body: <p>I'm trying to open up a remote desktop session programmatically in C#. I found <a href="https://www.codeproject.com/Articles/43705/Remote-Desktop-using-C-NET?fid=1551804&amp;df=90&amp;mpp=50&amp;prof=True&amp;sort=Position&amp;view=Normal&amp;spc=Compact" rel="noreferrer">this</a> tutorial, and followed it. I have a form that just consists of a <code>AxMSTSCLib.AxMsRdpClient8NotSafeForScripting</code> called <code>rdp</code>, and then I have the following code:</p>
  
  <pre><code>    public RDPViewer()
      {
          InitializeComponent();
          rdp.Server = "localhost";
          rdp.UserName = "&lt;userName&gt;";
  
          IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
          secured.ClearTextPassword = "&lt;password&gt;";
          rdp.Connect();
      }
  </code></pre>
  
  <p>(Username and password are hardcoded for now, this was just a first test to see how it worked)</p>
  
  <p>When I try to run it, though, I get an error popup:</p>
  
  <blockquote>
    <p>The connection cannot proceed because authentication is not enabled and the remote computer requires that authentication be enabled to connect.</p>
  </blockquote>
  
  <p>Googling this error finds several sites stating that the solution to this error is to go to <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp</code> and set the "SecurityLayer" value to 0, then reboot, but I've done this and still get the error.</p>
  
  <p>I have already set things up so it's possible to RDP to localhost, and I can connect using Remote Desktop Connection using the same credentials as I'm passing in the code.</p>