WinForms ActiveX RDP Client Issue With NLA

 ̄綄美尐妖づ 提交于 2019-12-24 08:18:17

问题


I'm trying to make a WinForms RDP client in C# using the RDP ActiveX control as a bit of a learning exercise. I can get everything working when the target server doesn't use Network Level Authentication (NLA), but when I try and configure the control to use 'EnableCredSspSupport', which I think is needed for NLA, I get the following error when running through the code:

An unhandled exception of type 'System.Windows.Forms.AxHost.InvalidActiveXStateException' occurred in AxInterop.MSTSCLib.dll

The code is:

        AxMsRdpClient9NotSafeForScripting rdp;

        rdp = new AxMsRdpClient9NotSafeForScripting();

        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

        ((System.ComponentModel.ISupportInitialize)(rdp)).BeginInit();
        rdp.Dock = System.Windows.Forms.DockStyle.Fill;
        rdp.Enabled = true;
        rdp.Location = new System.Drawing.Point(0, 0);
        rdp.Name = "rdp";
        rdp.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("rdp.OcxState")));
        rdp.Size = new System.Drawing.Size(828, 687);
        rdp.TabIndex = 0;

        rdp.AdvancedSettings9.AuthenticationLevel = 2;
        rdp.AdvancedSettings9.EnableCredSspSupport = true;

        MainsplitContainer.Panel2.Controls.Add(rdp);

        ((System.ComponentModel.ISupportInitialize)(rdp)).EndInit();

        rdp.Server = "XXX.XXX.XXX.XXX";
        rdp.Connect();

A lot of this code is mangled together from the following sources, but learning to code is usually standing on the shoulders of giants, right!?

http://msdn.microsoft.com/en-us/library/aa383022(VS.85).aspx https://searchcode.com/codesearch/view/3716390/

...And a couple more sources I don't have the reputation to share (First post!)

Any insights out there to help me on my way?

Thanks!

....Aaaand working code:

            AxMSTSCLib.AxMsRdpClient8NotSafeForScripting _RDPClient;
        _RDPClient = new AxMSTSCLib.AxMsRdpClient8NotSafeForScripting();

        MainsplitContainer.Panel2.Controls.Add(_RDPClient);

        ((System.ComponentModel.ISupportInitialize)(_RDPClient)).BeginInit();
        _RDPClient.Dock = System.Windows.Forms.DockStyle.Fill;
        _RDPClient.Enabled = true;
        _RDPClient.Location = new System.Drawing.Point(0, 0);
        _RDPClient.Name = "axMsTscAxNotSafeForScripting1";
        _RDPClient.OcxState = ((System.Windows.Forms.AxHost.State)(_RDPClient.OcxState));
        _RDPClient.Size = new System.Drawing.Size(579, 608);
        _RDPClient.TabIndex = 0;
        _RDPClient.AdvancedSettings8.EnableCredSspSupport = true;
        ((System.ComponentModel.ISupportInitialize)(_RDPClient)).EndInit();

        _RDPClient.OnDisconnected += new IMsTscAxEvents_OnDisconnectedEventHandler(axMsTscAx_OnDisconnected);


        _RDPClient.Server = IP;
        _RDPClient.Connect();

回答1:


Use :

CType(rdp, System.ComponentModel.ISupportInitialize).EndInit()
rdp.CreateControl()

Find your equivalent in C#



来源:https://stackoverflow.com/questions/27963640/winforms-activex-rdp-client-issue-with-nla

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!