我正在尝试使用RDP ActiveX控件在C#中制作WinForms RDP客户端作为学习练习。当目标服务器不使用网络级别身份验证 (NLA) 时,我可以让一切正常工作,但是当我尝试将控件配置为使用我认为 NLA 需要的"EnableCredSspSupport"时,我在运行代码时出现以下错误:
类型的未处理异常 "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).aspxhttps://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();
使用 :
CType(rdp, System.ComponentModel.ISupportInitialize).EndInit()
rdp.CreateControl()
在 C# 中查找等效项