【问题标题】:is it possible to fill in a windows credential prompt programmatically?是否可以以编程方式填写 Windows 凭据提示?
【发布时间】:2012-04-20 03:37:08
【问题描述】:

除了鲁棒性、稳定性和你不应该这样做的问题之外,有没有人通过代码填写过 Windows 凭据提示(所以看起来像这样:)

是否可以通过 Win32 API 或使用 SendKeys/发送鼠标/UI 自动化与这些对话框进行交互?任何人的任何想法/提示将不胜感激!

【问题讨论】:

标签: wpf winapi windows-authentication credentials


【解决方案1】:

使用AHK (Auto HotKey) 之类的东西,它是一种简单的语言,可以编译为 EXE,旨在实现键盘和鼠标的自动化。

或者您可以从 WPF 中执行此操作: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6fc7f1f6-f3e2-4b32-9d2b-9c7a2680e04a/

或者用户可以简单地勾选“记住我的凭据”

【讨论】:

    【解决方案2】:

    我最终使用了UI Automation framework,它允许我获取对凭据提示的引用,然后填写并以这种方式完成。

    代码sn-p:

    AutomationElement desktop = AutomationElement.RootElement;
    //get all windows on the desktop
    AutomationElementCollection windows = desktop.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
             foreach (AutomationElement window in windows)
            {
                if (window.Current.ClassName.Equals("#32770"))   //security dialog
                {
    
                    // access the appropriate AutomationElements to enter credentials here
    
                }
            }
    

    要与元素交互,您需要获取适当的 Pattern 对象并调用其方法(例如,文本框有一个 ValuePattern,它有一个 .SetValue() 方法。

    我还使用 UISpy 查找 ClassNames、AutomationIds 等的所有值,以帮助通过 .FindAll() 和 PropertyConditions 对象找到正确的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多