首页 新闻 会员 周边

NET远程桌面对 COM 组件的调用返回了错误 HRESULT E_FAIL

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-10-07 15:58

各位有没有遇到多个IP且第一个可以远程的,重启电脑后程序第一次运行会出错,再次、三次运行都正常,即开机后第一次不正常,后面都正常了。

请教各位为什么开机后第一次会出错?

代码如下:

public bool MstscConnectable(string Server)

{//多个IP时循环调用此方法

try

{

axMsRdpClient4a1.Server = Server;

MstscConnecting = true;

axMsRdpClient4a1.Connect();

while (MstscConnecting)

{

Thread.Sleep(1000);

}

}

catch (Exception ex)

{

WriteLog("Server:{0} 远程桌面访问出错,错误信息:{1}", axMsRdpClient4a1.Server, ex.Message);

}

 

return MstscRetValue == 1;

}

private void axMsRdpClient4a1_OnConnecting(object sender, EventArgs e)

{

WriteLog("Server:{0} Connecting...", axMsRdpClient4a1.Server);

MstscRetValue = 0;

}

private void axMsRdpClient4a1_OnConnected(object sender, EventArgs e)

{

WriteLog("Server:{0} Connected.", axMsRdpClient4a1.Server);

MstscRetValue = 1;

MstscConnecting = false;

axMsRdpClient4a1.Disconnect(); //连接成功后主动断开连接

}

private void axMsRdpClient4a1_OnDisconnected(object sender, AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEvent e)

{

if (MstscRetValue == 0) //MstscRetValue=0表示之前未连接成功

{

WriteLog("Server:{0} Disconnected", axMsRdpClient4a1.Server);

MstscRetValue = 2;

MstscConnecting = false;

}

}

 

循环调用时打印信息如下,

首次运行时:

2011-09-07 09:44:06 开始刷新远程桌面...

2011-09-07 09:44:07 Server:192.168.88.186 Connecting...

2011-09-07 09:44:18 Server:192.168.88.186 Connected.

2011-09-07 09:44:28 Server:192.168.88.186 远程桌面访问出错,错误信息:对 COM 组件的调用返回了错误 HRESULT E_FAIL。

2011-09-07 09:44:28 刷新远程桌面结束

再次、三次运行时:

2011-09-07 09:45:02 开始刷新远程桌面...

2011-09-07 09:45:02 Server:192.168.88.186 Connecting...

2011-09-07 09:45:04 Server:192.168.88.186 Connected.

2011-09-07 09:45:07 Server:192.168.88.6 Connecting...

2011-09-07 09:45:08 Server:192.168.88.6 Connected.

2011-09-07 09:45:08 刷新远程桌面结束

 

看首次运行时的错误信息的IP地址还是第一个,说明是在第一步axMsRdpClient4a1.Server = Server;设置IP时出错的,请教各位首次出错原因

wangd的主页 wangd | 初学一级 | 园豆:75
提问于:2011-09-07 10:31
< >
分享
所有回答(1)
0

看看系统日志,有没有什么出错信息

artwl | 园豆:16736 (专家六级) | 2011-09-19 11:41

我是把mstscax.dll转换成.net控件后使用的,已经不是win32组件了,看了系统日志,没发现有相关信息

支持(0) 反对(0) wangd | 园豆:75 (初学一级) | 2011-09-22 12:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册