Search code examples
c#winformsactivexterminal-servicesterminal-services-gateway

How to use Terminal Services Gateway with the IMsRdpClient6 ActiveX Control?


I am hosting the IMsRdpClient6 ActiveX control in my WinForms application in order to make connections to remote machines.

I have setup a terminal services gateway machine, and I can successfully use it.

I want to get my ActiveX control to use this gateway. I have set the Gateway options, but connection fails with no error that I can see. Here is the code that I am using:

        MSTSCLib6.IMsRdpClient6 client6 = RdpClient.GetOcx() as MSTSCLib6.IMsRdpClient6;            

        if (client6 != null)
        {
            MSTSCLib6.IMsRdpClientTransportSettings2 transport = client6.TransportSettings2;

            if (Convert.ToBoolean(transport.GatewayIsSupported) == true)
            {
                client6.TransportSettings.GatewayHostname = "mygateway";
                client6.TransportSettings.GatewayUsageMethod = 2;

                client6.TransportSettings.GatewayCredsSource = 0;
                client6.TransportSettings.GatewayUserSelectedCredsSource = 0;
                client6.TransportSettings2.GatewayDomain = "mydomain";
                client6.TransportSettings2.GatewayPassword = "mypassword";
                client6.TransportSettings2.GatewayUsername = "myusername";
            }
        }

Solution

  • The answer to this was to omit the GatewayUserSelectedCredsSource and to include GatewayProfileUsageMethod = 1;

            MSTSCLib6.IMsRdpClient6 client6 = RdpClient.GetOcx() as MSTSCLib6.IMsRdpClient6;            
    
            if (client6 != null)
            {
                MSTSCLib6.IMsRdpClientTransportSettings2 transport = client6.TransportSettings2;
    
                if (Convert.ToBoolean(transport.GatewayIsSupported) == true)
                {
                    client6.TransportSettings.GatewayHostname = "mygateway";
                    client6.TransportSettings.GatewayUsageMethod = 1;
    
                    client6.TransportSettings.GatewayCredsSource = 0;
                    client6.TransportSettings.GatewayProfileUsageMethod = 1;
                    client6.TransportSettings2.GatewayDomain = "mydomain";
                    client6.TransportSettings2.GatewayPassword = "mypassword";
                    client6.TransportSettings2.GatewayUsername = "myusername";
                }
            }