自动键入RDP连接的密码(CredentialUIBroker)

问题描述 投票:0回答:1

作为练习,我正在尝试使用FlaUI自动键入RDP凭据。我的操作系统是Windows 10。

我能够启动mstsc.exe并在此窗口中键入:

mstsc window

但是后来我得到了这个窗口,但在任何地方都找不到它:

Credential Manager UI Host window

这不是mstsc窗口,即使它在上方显示为模式窗口:mstsc始终只有一个窗口。显然,这是“ Credential Manager UI主机”的窗口,但是该进程有零个窗口。

即使在任务管理器中,它也在后台任务中列出,而不在应用程序部分中列出。FlaUI Inspect根本看不到它。

顺便说一下,这是我的代码:

var CurrentAutomation = new UIA3Automation();
var Process = Application.Attach(Process.GetProcessesByName("CredentialUIBroker")[0]);
var Windows = Process.GetAllTopLevelWindows(CurrentAutomation); // 0 elements

如何获得此窗口的句柄并使用FlaUI访问其文本框?

c# testing rdp flaui
1个回答
0
投票

原来,只是知道“窗口”的名称,这就是凭据对话框Xaml主机;也可以使用FlaUI Inspect找到它。

一旦完成mstsc部分,然后出现“ Windows安全性”窗口,您就可以继续执行此示例代码:

// Declare all variables, which might be method parameters instead
var Password = "MyLamePassword";
var MaxTimeout = new TimeSpan(10 * 1000 * 2000);
var CurrentAutomation = new UIA3Automation();
var Desktop = CurrentAutomation.GetDesktop();

// Get the window, using a Retry call to wait for it to be available
var CredentialWindow = Retry
    .WhileEmpty(
        () => Desktop.FindAllDescendants(f => f.ByClassName("Credential Dialog Xaml Host")),
        timeout: MaxTimeout,
        throwOnTimeout: true)
    .Result[0];

// Get the password box
AutomationElement PasswordBox = null;
Retry.WhileNull(
    () => PasswordBox = CredentialWindow.FindFirstDescendant(f => f.ByName("Password").And(f.ByControlType(ControlType.Edit))),
    timeout: MaxTimeout,
    throwOnTimeout: true);

// Type the password
PasswordBox.FocusNative();
Keyboard.Type(Password);

// I have some Retry code here too, just to check that the password is actually typed, and type Enter after it. 

CurrentAutomation.Dispose();
© www.soinside.com 2019 - 2024. All rights reserved.