Accessing Remote Desktop

2019-07-13 12:19发布

I'm trying to open up a remote desktop session programmatically in C#. I found this tutorial, and followed it. I have a form that just consists of a AxMSTSCLib.AxMsRdpClient8NotSafeForScripting called rdp, and then I have the following code:

    public RDPViewer()
    {
        InitializeComponent();
        rdp.Server = "localhost";
        rdp.UserName = "<userName>";

        IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
        secured.ClearTextPassword = "<password>";
        rdp.Connect();
    }

(Username and password are hardcoded for now, this was just a first test to see how it worked)

When I try to run it, though, I get an error popup:

The connection cannot proceed because authentication is not enabled and the remote computer requires that authentication be enabled to connect.

Googling this error finds several sites stating that the solution to this error is to go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp and set the "SecurityLayer" value to 0, then reboot, but I've done this and still get the error.

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.

2条回答
【Aperson】
2楼-- · 2019-07-13 13:17

This worked for me, without changing the settings of the remote computer:

rdpClient.AdvancedSettings9.EnableCredSspSupport = true;

See: enabling Credential Security Support Provider for authentication: https://technet.microsoft.com/en-us/library/ff393716(v=ws.10).aspx

查看更多
神经病院院长
3楼-- · 2019-07-13 13:20

I found the problem in the end. Turns out it was set in Group Policy, rather than in the registry. I found the answer here - The relevant Group Policy setting is "Require use of specific security layer for remote (RDP) connections", and is found at Computer Configuration\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Security.

By changing the Security Layer option in that policy from SSL (TLS 1.0) to RDP, I was able to connect.

查看更多
登录 后发表回答