Software RDP Login and SendMessage

I need to program RDP on a virtual machine (XP SP3 / .NET3.5 / VS 2008), (the credentials were saved in a .rdp file) and conduct user interface automation testing. Due to our domain security, I need to programmatically respond "ok" to an interactive login. I can access other Windows and SendMessages dialogs for buttons, etc. After logging in, but I was not able to get my SendMessage to work on this initial screen. I used spy ++ to capture what is actually sent when I press the enter button, and I seem to be able to duplicate these messages when I look at the answer in the spy ++ log when my program starts, but no matter which option I use in the message, nothing happens, I would like to knowis it even possible to do this programmatically or does the OS prevent such automation due to security issues?

Messages that I see in spy ++ when I press the enter button (on this initial screen it seems that 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 execute the code below and watch the messages sent to IHWindowClass (below hwnd6), I see that I am generating the above messages in this window. Any help would be appreciated!

Here are the relevant 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);'
+3
source share
2 answers

You are almost there, there are a few other messages that you need to send in order to get an RDP session ready to accept keyboard input. With Spy ++, you should have seen some more messages being sent.

"", (, , RDP) :

SendMessage(cWind, (int)WM.IME_SETCONTEXT, new UIntPtr(0x00000001), new UIntPtr(0xC000000F));
SendMessage(cWind, (int)WM.IME_NOTIFY, new IntPtr(0x00000002), new IntPtr(0x00000000));
Thread.Sleep(1);

SendMessage(cWind, (int)WM.SETFOCUS, new UIntPtr(0x00203794), new UIntPtr(0x00000000));
Thread.Sleep(1);
//Random keypress
SendMessage(cWind, (int)WM.KEYDOWN, new UIntPtr(0x000000FF), new UIntPtr(0x00000001));
SendMessage(cWind, (int)WM.KEYUP, new UIntPtr(0x00000041), new UIntPtr(0xC0000001));
Thread.Sleep(1);
//A key presses
SendMessage(cWind, (int)WM.KEYDOWN, new IntPtr(0x00000041), new IntPtr(0x001E0001));
SendMessage(cWind, (int)WM.KEYUP, new UIntPtr(0x00000041), new UIntPtr(0xC01E0001));

, Spy ++ , , , . , "" setfocus/setcontext, . (Spy ++ )

0

@Spike, IME_SETCONTEXT IME_NOTIFY. , , "", VK_A-VK_Z.

                SendMessageKey.SimulateKey.SendMessage((IntPtr)hwnd, SendMessageKey.MessageCode.WM_IME_SETCONTEXT, 0x00000001, 0xc000000f);
                SendMessageKey.SimulateKey.SendMessage((IntPtr)hwnd, SendMessageKey.MessageCode.WM_IME_NOTIFY, 0x00000002, 0x00000000);
                SendMessageKey.SimulateKey.SendMessage((IntPtr)hwnd, SendMessageKey.MessageCode.WM_SETFOCUS, 0x00000000, 0x00000000);

VK_A (), Winspector WM_KEYDOWN + WM_KEYUP / 255. , . , , .

0

Source: https://habr.com/ru/post/1751240/


All Articles