首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >自动键入RDP连接密码(CredentialUIBroker)

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

Stack Overflow用户
提问于 2020-04-02 09:31:38
回答 1查看 911关注 0票数 1

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

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

但是我拿到这扇窗户,却找不到它:

它不是mstsc窗口,尽管它上方显示为一个模态窗口: mstsc总是只有一个窗口。显然这是“凭证管理器UI主机”的窗口,但是这个过程.没有窗户。

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

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

代码语言:javascript
运行
复制
var CurrentAutomation = new UIA3Automation();
var Process = Application.Attach(Process.GetProcessesByName("CredentialUIBroker")[0]);
var Windows = Process.GetAllTopLevelWindows(CurrentAutomation); // 0 elements

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-02 16:36:22

事实证明,这只是知道“窗口”的名称的问题,该窗口是凭据Dialog主机;而且,可以使用FlaUI检查找到它。

一旦完成了mstsc部分,并出现了"Windows Security“窗口,您可以继续使用以下示例代码:

代码语言:javascript
运行
复制
// 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();
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60988380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档