我需要以编程方式 RDP 到虚拟机(XP SP3 / .NET3.5 / VS 2008),(凭据已保存在 .rdp 文件中)并进行 UI 自动化测试。由于我们的域安全性,我需要以编程方式对交互式登录回答“确定”。登录后,我可以访问其他对话窗口和将消息发送到按钮等,但我无法让我的 SendMessage 在此初始屏幕上工作。当我按下回车键时,我使用 spy++ 来捕获实际发送的内容,当我在运行程序时查看 spy++ 日志中的响应时,我似乎能够复制这些消息,但无论我在消息中使用什么变体都没有任何反应. 我想知道是否有可能以编程方式执行此操作,或者操作系统是否由于安全问题阻止了这种自动化?
当我按下回车按钮时,我在 spy++ 中看到的消息(在那个初始屏幕上,似乎任何键都可以)我看到:
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
当我练习下面的代码并观察发送到 IHWindowClass(hwnd6 below) 的消息时,我看到我向该窗口生成了上述消息。任何帮助,将不胜感激!
以下是代码的相关部分:
'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);'