Search code examples
c#.netwpfremote-desktoprdp

How to remove the untrusted certificate window when connecting to RDP?


I use AxMsRdpClient7NotSafeForScripting. So I'm connecting:

        _rdp.Server = "";
        _rdp.UserName = "";
        _rdp.AdvancedSettings7.ClearTextPassword = "";

        _rdp.ColorDepth = 24;
        _rdp.AdvancedSettings7.SmartSizing = true;
        _rdp.AdvancedSettings7.AuthenticationLevel = 2;
        _rdp.AdvancedSettings7.EnableCredSspSupport = true;
        
        _rdp.AdvancedSettings7.RedirectDevices = true;
        _rdp.AdvancedSettings7.RedirectDrives = true;

        _rdp.Width = Convert.ToInt32(this.ActualWidth);
        _rdp.Height = Convert.ToInt32(this.ActualHeight);
        _rdp.DesktopWidth = Convert.ToInt32(this.ActualWidth);
        _rdp.DesktopHeight = Convert.ToInt32(this.ActualHeight);

where _rdp is:

class RdpControl : AxMSTSCLib.AxMsRdpClient7NotSafeForScripting
{
    public RdpControl() : base() { }

    protected override void WndProc(ref System.Windows.Forms.Message m)
    {
        // Fix for the missing focus issue on the rdp client component
        if (m.Msg == 0x0021 && !this.ContainsFocus) // WM_MOUSEACTIVATE
            this.Focus();

        base.WndProc(ref m);
    }
}

I found this in the msdn documentation, but for some reason this property is not in AxMsRdpClient.

https://i.sstatic.net/0yaZR.png


Solution

  • This is a bit stupid. Because I found the answer while rereading my question xD.

    It is necessary to set the Authentication Level property to 0, or simply delete it:

    _rdp.AdvancedSettings7.AuthenticationLevel = 0;