我正在尝试使用 Windows 窗体 anf 创建一些 RDP 客户端AxMsTscAxNotSafeForScripting
我有以下方法:
_rdpList = new List<AxMsTscAxNotSafeForScripting>();
public bool addRDP(string ip, string username, string pass)
{
for (int i = 0; i < number ; i++)
{
if (_rdpList[i].Connected.ToString() != "1")
{
try
{
_rdpList[i].Server = ip;
_rdpList[i].UserName = username;
IMsTscNonScriptable secured = (IMsTscNonScriptable) _rdpList[i].GetOcx());
secured.ClearTextPassword = pass;
_rdpList[i].Connect();
_picList[int.Parse(_rdpList[i].Name)].ImageLocation = greenPath;
return true;
}
catch (Exception Ex)
{
MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + ip + " Error: " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
我从线程调用此方法,当它尝试执行以下操作时:IMsTscNonScriptable secured = (IMsTscNonScriptable) _rdpList[i].GetOcx());
它失败并出现以下错误:
无法将“System.__ComObject”类型的 COM 对象转换为接口类型“MSTSCLib.IMsTscNonScriptable”。此操作失败,因为 IID 为“{C1E6743A-41C1-4A74-832A-0DD06C1C7A0E}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE)) .
我整天都在研究它,但我无法理解这个问题?
奇怪的是,如果我从 Windows 窗体事件(例如按钮单击)调用此方法,每项工作都很好,当我从 WCF 服务调用此方法时会出现唯一的问题。
请帮忙。