RDP Login and SendMessage

Discussion in 'MFC' started by carlf7000, Jun 22, 2010.

  1. carlf7000

    carlf7000 New Member

    Joined:
    Jun 22, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    I have the need to programmatically RDP to a virtual machine(XP SP3 / .NET3.5 / VS 2008), (credentials have been saved in .rdp file) and do UI automation testing. Because of our domain security, I need to programmatically answer 'ok' to the interactive logon. I am able to access other dialogue Windows and SendMessages to buttons, etc, after login, but I have not been able to get my SendMessage to work on this initial screen. I used spy++ to capture what actually gets sent when I press enter and I seem to be able to duplicate those messages as I view the response in the spy++ log as I run my program, but no matter what variant I use in the message nothing happens.
    I would like to know if it is even possible to programmatically do this or does the OS prevent this kind of automation due to security issues?

    The messages I see in spy++ when I hit the enter button( on that initial screen it seems any key will do) I see:

    WM_KEYDOWN nVirtKey:00FF cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 Up:0
    WM_KEYUP nVirtKey:00FF cRepeat:1 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:1 Up:1

    When I exercise the code below and watch the messages sent to IHWindowClass(hwnd6 below) I see I generate the above messages to that window. Any help would be appreciated!


    Here are the pertinent sections of the code:


    UIntPtr ip = new UIntPtr(0x0D); //ENTER
    UIntPtr ip2 = new UIntPtr(0xFF); //00FF
    UIntPtr kyDwnlParam = new UIntPtr(0x001);
    UIntPtr kyUplParam = new UIntPtr(0xc0000001);

    // used UISpy to get these class names...
    string lpszParentClass = "TscShellContainerClass";
    string lpszParentWindow = "test2 - test2 - Remote Desktop Connection";
    string lpszClass2 = "TscShellAxHostClass";
    string lpszClass3 = "ATL:2D33D580";
    string lpszClass4 = "UIMainClass";
    string lpszClass5 = "UIContainerClass";
    string lpszClass6 = "IHWindowClass";


    hWnd2 = FindWindowEx(ParenthWnd, IntPtr.Zero, lpszClass2, IntPtr.Zero);
    hWnd3 = FindWindowEx(hWnd2, IntPtr.Zero, lpszClass3, IntPtr.Zero);
    hWnd4 = FindWindowEx(hWnd3, IntPtr.Zero, lpszClass4, IntPtr.Zero);
    hWnd5 = FindWindowEx(hWnd4, IntPtr.Zero, lpszClass5, IntPtr.Zero);
    hWnd6 = FindWindowEx(hWnd5, IntPtr.Zero, lpszClass6, IntPtr.Zero);

    string hexValue = hWnd6.ToString("X"); //Convert to hex to use find in spy++

    SetForegroundWindow(hWnd6); // for good measure....

    // tried this....

    SendMessage(hWnd6, (uint)WindowsUtilities.WindowsMessages.WM_KEYDOWN, ip2, kyDwnlParam);
    SendMessage(hWnd6, (uint)WindowsUtilities.WindowsMessages.WM_KEYUP, ip2, kyUplParam);

    // tried this....
    SendMessage(hWnd6, (uint)WindowsUtilities.WindowsMessages.WM_KEYDOWN, ip, kyDwnlParam);
    SendMessage(hWnd6, (uint)WindowsUtilities.WindowsMessages.WM_KEYUP, ip, kyUplParam);

    // tried this...
    SendMessage(hWnd6, (uint)WindowsUtilities.WindowsMessages.WM_CHAR, ip, UIntPtr.Zero);
    SendMessage(hWnd6, (uint)WindowsUtilities.WindowsMessages.WM_CHAR, ip, UIntPtr.Zero);
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice