Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I wrote a simple rdp App with C#, i'am using MSTSCLIB. This works fine for me.

//hide form border
    this.FormBorderStyle = FormBorderStyle.None;

    //server and username
    rdp.Server = "*********";
    rdp.UserName = "*********";

    //password
    IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
    secured.ClearTextPassword = "***********";

    //resolution
    rdp.DesktopHeight = 1080;
    rdp.DesktopWidth = 1920;

    //rdp  options
    rdp.AdvancedSettings8.AuthenticationLevel = 2;

    //connect
    rdp.Connect();


Sometimes the user is allready logged on to the remote workstation and I receive a Windows Dialog "The specified Windows account is already logged in. ...".

I need help with a solution to confirm that Windows dialog automatically.

What I have tried:

So the first idea was to set the application in foreground:

//Set window as foreground window
                Process processes = Process.GetCurrentProcess();

                //MessageBox.Show(processes.ProcessName);
                
                IntPtr windowhandle = processes.MainWindowHandle;
                SetForegroundWindow(windowhandle);


And the second step is to get the windows Handle ID with spy++ and use FindWindow() to use SendMessage() to close the MessageBox Handle.

//Get the MessageBox handle
            IntPtr handle = FindWindow("?????????", null);
            MessageBox.Show("Hanlde1: " + handle.ToString() + "\n");

            //Get the Text window handle
            IntPtr txtHandle = FindWindowEx(handle, IntPtr.Zero, "Static",  null);
            MessageBox.Show("\ttext handle: " + txtHandle.ToString() + "\n");
            int len = GetWindowTextLength(txtHandle);
            StringBuilder sb = new StringBuilder();

            //Get the text
            GetWindowText(txtHandle, sb, len + 1);
            MessageBox.Show("\ttext: " + sb.ToString() + "\n\n");

            //close the messagebox
            SendMessage(new HandleRef(null, handle), WM_CLOSE, IntPtr.Zero, IntPtr.Zero);


So my problem is, that I can't get the Handle ID from spy++ for the Dialog in the RDP connection. It shows me only the ID from the parent Window not from the Windows Dialog.

So my first question is: Is that the correct way to handle this dialog window? And Second Question: How can I receive the correct Handle ID of the Dialog Window in the RDP Session.

Many Thanks.

Hagen
Posted
Updated 11-Apr-18 4:26am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900