プログラムで仮想マシン (XP SP3 / .NET3.5 / VS 2008) に RDP し (資格情報は .rdp ファイルに保存されています)、UI 自動化テストを行う必要があります。ドメインのセキュリティのため、対話型ログオンに対してプログラムで「OK」と答える必要があります。ログイン後、他のダイアログ ウィンドウやボタンなどへの SendMessages にアクセスできますが、この初期画面で SendMessage を機能させることができませんでした。私は spy++ を使用して、Enter キーを押したときに実際に送信されるものをキャプチャしました。プログラムを実行しているときに spy++ ログで応答を表示すると、これらのメッセージを複製できるようですが、メッセージで使用するバリアントに関係なく、何も起こりません. プログラムでこれを行うことさえ可能かどうか、またはセキュリティの問題のためにOSがこの種の自動化を妨げているかどうかを知りたいですか?
Enterボタンを押したときに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) に送信されたメッセージを見ると、上記のメッセージがそのウィンドウに生成されていることがわかります。どんな助けでも大歓迎です!
コードの関連セクションは次のとおりです。
'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);'