C# C中远程桌面连接出现奇怪的H_结果E_失败错误#

C# C中远程桌面连接出现奇怪的H_结果E_失败错误#,c#,com,rdp,C#,Com,Rdp,我正在使用C#中的com组件MicrosoftRDPClientControlVersion8连接到终端服务器和远程桌面 代码如下所示: if (rdp.Connected.ToString() == "1") { rdp.Disconnect(); } rdp.Server = userDetails.RoleMachine; rdp.UserName = userDetails.UserName; IMsTscNonScriptable secured = (IMsTscNonScrip

我正在使用C#中的com组件MicrosoftRDPClientControlVersion8连接到终端服务器和远程桌面

代码如下所示:

if (rdp.Connected.ToString() == "1")
{
  rdp.Disconnect();
}
rdp.Server = userDetails.RoleMachine;
rdp.UserName = userDetails.UserName;
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ResetPassword();
secured.ClearTextPassword = userDetails.Password;
这在第一次对远程桌面或终端服务服务器起作用,但在随后的调用中失败,出现“H_RESULT E_FAIL”错误,堆栈跟踪如下

如何允许某人从同一表单重新连接到其他地方(即,在更改属性和尝试连接()之前需要清理哪些内容?)


答案很简单

对Disconnect()的调用是异步的

我必须处理ActiveX控件的OnDisconnect事件,直到它触发(例如完全断开连接)后才尝试再次连接()

at MSTSCLib.IMsRdpClient7.set_Server(String pServer)
at AxMSTSCLib.AxMsRdpClient7.set_Server(String value)
at RDP.FrmRemote.Connect() in \\..\FrmRemote.cs:line 56
at RDP.FrmRemote.Operations1_Click(Object sender, EventArgs e) in  \\...\FrmRemote.cs:line 157
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32  clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)