1

Issues of robustness, stability and you shouldn't do this aside, has anyone ever filled in a windows credential prompt via code (so that's one that looks like this:)

windows security prompt

Is it possible to interact with these dialog boxes through Win32 APIs, or using SendKeys/send mouse / UI Automation? Any ideas / tips anyone has would be greatly appreciated!

Henry C
  • 4,781
  • 4
  • 43
  • 83
  • it looks like this SO question (http://stackoverflow.com/q/2841120/167018) might be what i'm looking to do - will update with answer once I get it going :) – Henry C Apr 22 '12 at 22:33

2 Answers2

1

I ended up using the UI Automation framework, which allowed me to grab a reference to the credential prompt and then fill it out and complete it that way.

Code snippet:

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

            }
        }

To interact with an element, you grab the appropriate Pattern object and call its methods (eg Textboxes have a ValuePattern which has a .SetValue() method.

I also used UISpy to find all the values for things like ClassNames, AutomationIds, etc to help find the correct item through .FindAll() and PropertyConditions objects.

Henry C
  • 4,781
  • 4
  • 43
  • 83
0

Use something like AHK (Auto HotKey) it is a simple language that can be compiled to an EXE and is designed for automating the keyboard and mouse.

Or you could do it from WPF: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6fc7f1f6-f3e2-4b32-9d2b-9c7a2680e04a/

Or users could simply tick "Remember my credentials"

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321