I am trying to create some RDP client with Windows form anf AxMsTscAxNotSafeForScripting
I have the following method:
_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);
}
}
}
I call this method from thread and when it try to do :IMsTscNonScriptable secured = (IMsTscNonScriptable) _rdpList[i].GetOcx());
It fails with the following error :
Unable to cast COM object of type 'System.__ComObject' to interface type 'MSTSCLib.IMsTscNonScriptable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C1E6743A-41C1-4A74-832A-0DD06C1C7A0E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I working on it all day long but I couldn't understand the issue?
The weird thing is if I invoke this method from windows form event ( such as button click) EVERY this work fine the only issue occur when i invoke this method from my WCF service.
Please help.