我正在尝试使用RDP ActiveX控件在C#中创建一个WinForms RDP客户端作为一个学习练习。当目标服务器不使用网络级别身份验证(NLA)时,我可以使一切正常工作,但是当我尝试将控件配置为使用'EnableCredSspSupport'时,我认为NLA需要它,我在运行时遇到以下错误代码:
未处理的类型异常 发生'System.Windows.Forms.AxHost.InvalidActiveXStateException' AxInterop.MSTSCLib.dll
代码是:
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();
这些代码很多都是从以下来源中篡改过来的,但学习编码通常是站在巨人的肩膀上,对吧!?
http://msdn.microsoft.com/en-us/library/aa383022(VS.85).aspx https://searchcode.com/codesearch/view/3716390/
......还有更多来源我没有分享的声誉(第一篇文章!)
有什么见解可以帮助我吗?
谢谢!
.... Aaaand工作代码:
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();
答案 0 :(得分:1)
使用:
CType(rdp, System.ComponentModel.ISupportInitialize).EndInit()
rdp.CreateControl()
在C#中找到您的对应物