0

I'm trying to check my RDP credentials using c#

Here is my reference : Remote Desktop using C#.NET

And here is what I've done so far :

private void testBtn_Click(object sender, EventArgs e) {
    try {
        AxMsRdpClient8NotSafeForScripting ax = new AxMsRdpClient8NotSafeForScripting();
        ax.OnLoginComplete += Ax_OnLoginComplete;
        ax.OnLogonError += Ax_OnLogonError;
        ax.OnFatalError += Ax_OnFatalError;
        ax.Size = new Size(1, 1);
        ax.CreateControl();
        ax.Server = ipTbx.Text;
        ax.UserName = userNameTbx.Text;
        MsRdpClient8NotSafeForScripting sec = (MsRdpClient8NotSafeForScripting)ax.GetOcx();
        sec.AdvancedSettings8.ClearTextPassword = passwordTbx.Text;
        sec.AdvancedSettings8.EnableCredSspSupport = true;
        ax.Connect();
    } catch (Exception ex) {
        MessageBox.Show("Error : " + ex.Message);
    }
}

private void Ax_OnFatalError(object sender, IMsTscAxEvents_OnFatalErrorEvent e) {
    SaySomething();
}

private void Ax_OnLogonError(object sender, IMsTscAxEvents_OnLogonErrorEvent e) {
    SaySomething();
}

private void Ax_OnLoginComplete(object sender, EventArgs e) {
    SaySomething();
}

public void SaySomething() {
    MessageBox.Show("Worked!");
}

As you can see, I've done everything in the article way. But nothing happens, even an exception would be worthy.

Any Idea?

Hooman Limouee
  • 1,143
  • 2
  • 21
  • 43
  • "Drag the newly added control from toolbox to the form" is the critical missing step. CreateControl() is not a substitute, these activex controls require more initialization and often don't work at all when they don't have a parent window. They need it to raise events. Best way to stay out of trouble is to put it on a form and Show() it but just preventing it from getting visible. Override SetVisibleCore() as [shown here](https://stackoverflow.com/a/1732294/17034) – Hans Passant May 31 '19 at 10:17
  • @HansPassant - Uh, seems like you are right, I was doing it by studying a same project, found that I missed a line which was adding its control to the form. Thank you – Hooman Limouee Jun 02 '19 at 08:58

0 Answers0