2

I Have recently searched the web trying to find answers on how to create and run a MSTSC RDP session in WPF, Finally got all what i needed, created the AxMSTSCLib dll and added that and MSTSCLib dll as a reference into the project. but after creating a user control and adding a windows form host, running the application does not display the MSTSC Active X Control.

If i swap the RDP control to something like a TextBlock it displays so i know it can't be something to do with the user control as such. An event when loading the user control fires and does the below;

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        try
        {
            AxMsRdpClient9NotSafeForScripting rdp = new AxMsRdpClient9NotSafeForScripting();
            //AxMsTscAxNotSafeForScripting rdp = new AxMsTscAxNotSafeForScripting();
            //AxMsRdpClient9 rdp = new AxMsRdpClient9();
            rdp.CreateControl();

            rdp.AdvancedSettings9.AuthenticationLevel = 2;
            rdp.AdvancedSettings9.EnableCredSspSupport = true;
            rdp.AdvancedSettings9.NegotiateSecurityLayer = false;
            rdp.Server = server;
            rdp.UserName = "jwilson-hogg";
            rdp.DesktopHeight = 768;
            rdp.DesktopWidth = 1024;
            rdp.Connect();

            RDP_Host.Child = rdp as System.Windows.Forms.Control;

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message + "\n\n" + ex.InnerException, "Error Trying to connect to: " + server);
        }
    }

But nothing actually appears on the application. I have googled and tried to change bits and bobs in the code some errors are thrown but 9 times out of 10 the control does not show the MSTSC session.

UPDATE 1: I have tried moving the rdp.CreateControl() line around incase the control is being created to early, now i am getting the error: "'System.Windows.Forms.AxHost.InvalidActiveXStateException' occurred in AxMSTSCLib.dll"

0 Answers0