Filling Out a Windows Credentials Prompt With UIAutomation / C#

23 April 2012

Back in the day, there used to be a thing called the Microsoft Active Accessibility, which programs like screenreaders used to interface and interact with Windows and other applications. The successor to this, introduced in .NET 3.0, is the UI Automation Framework, which allows us to get a reference to pretty much any window, dialog box, text box / buttons and do interact with those elements.

Which means, that if you need to fill in a windows credential prompt, you can use the UIAutomation code!

Take a look at my StackOverflow question for starter code snippet - and a few random points:

  • By default, the requisite .dlls to use the Automation framework don't come up in the .NET tab when you're adding a reference - you'll need to add them from C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0
  • I had an issue where the TogglePattern for a checkbox wouldn't work (on a specific checkbox), so I ended up using .SetFocus() and SendKeys.SendWait(" "); to toggle it instead
  • I highly recommend using UISpy to help you out, a utility that comes with the Windows SDK - you can find a mirror here
  • Just a guess (since I haven't done any investigation around this) but this may or may not live in some form within Windows 8, since when you create a new project you'll see a whole bunch of AutomationId properties in the default .xaml and templates

Have fun with all those AutomationElements! :D

Tags: .NET, C#, credentials, UIAutomation, UISpy

Add a Comment

No Comments