RDP Client - AxHost.InvalidActiveXStateException
I am working on an application that will optimize my work, with multiple RDP connections to my servers. At this point, I will like to make one window form that will show me all my servers. With my relevant knowledge - I want to add a program item AxMsRdpClient2
or AxMsTscAxNotSafeForScripting
to my Windows Form. On startup I have Form1 where I save my credentials (IP, USER, PASS) and with a simple one FOR
I rebuild to add ActiveX Client to my Form2 and connect to servers.
And here I have a problem. Let's see my code below.
call from form1 ()>
var btt = new RunRDP();
for (int i = 0; i < 15; i++)
{
btt.PozitionMaster();
}
RunRDP class:
private static int _count;
private static int _row = 4;
private static int _colum = 4;
private static int _objId;
public void PozitionMaster()
{
if (_count != 6)
{
UInitializer(_objId++, _row, _colum);
_row += 196;
_count++;
}
else
{
_colum += 196;
_row = 4;
_count = 0;
}
}
UInitializer function:
public AxMsRdpClient2 rdpClient;
public void UInitializer(int id, int x, int y)
{
Form2 ippo = new Form2();
rdpClient = new AxMsRdpClient2();
rdpClient.UserName = "username";
rdpClient.Server = "192.168.0.100";
rdpClient.Height = y;
rdpClient.Width = x;
rdpClient.BeginInit();
rdpClient.CreateControl();
if (ippo.InvokeRequired)
{
ippo.Invoke(new Action(() => ippo.Controls.Add(rdpClient)));
ippo.Invoke(new Action(() => ippo.Update()));
}
else
{
ippo.Controls.Add(rdpClient);
}
//this.Controls.Add(rdpClient);
rdpClient.AdvancedSettings2.RDPPort = 3389;
rdpClient.AdvancedSettings2.ClearTextPassword = "hello_rdp";//
rdpClient.ColorDepth = 16;//
rdpClient.FullScreen = false;//
rdpClient.Connect();
}
get this error:
An unhandled exception of type 'System.Windows.Forms.AxHost.
InvalidActiveXStateException' occurred in AxInterop.MSTSCLib.dll
{"Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown."}
+3
source to share