我需要以編程方式將RDP指向虛擬機(XP SP3/.NET3.5/VS 2008),(證書已保存在.rdp文件中)並進行UI自動化測試。由於我們的域安全性,我需要以編程方式回答交互式登錄的「確定」。我可以在登錄後訪問其他對話窗口和SendMessages按鈕等,但我無法讓我的SendMessage在此初始屏幕上工作。我用spy ++來捕獲當我按下Enter鍵時實際發送的內容,當我在運行我的程序時在間諜++日誌中查看響應時,似乎能夠複製這些消息,但無論我在消息中使用什麼變體,都不會發生任何事情。 我想知道是否甚至有可能以編程方式執行此操作,還是操作系統由於安全問題而阻止了這種自動化?編程RDP登錄和SendMessage
我在間諜++看到,當我按下回車鍵的消息(初始畫面上似乎任何鍵都可以)我看到:
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)我看到我生成上述消息到該窗口。任何幫助,將不勝感激!
這裏是代碼的相關章節:
'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);'