0

Below is my code

AutomationElementCollection panes = AutomationElement.RootElement.FindAll(TreeScope.Children, paneCondition);

Basically the above code pulls for all open windows on my desktop. It works fine when run locally using Debug in Visual Studio IDE but there is a problem when deployed to IIS.

The AutomationElementCollection is turning out to be empty when in IIS, in contrast when run in Visual Studio which the count of items in the collection is not 0.

Now how can I fix this problem? Any help would be appreciated :)

BTW, what I'm trying to do is to automate the login of Windows Security Prompt.

  • 1
    This will (hopefully) never work. IIS is a service, it can't interact with the local desktop (maybe it was possible with old Windows version, or if you tweak it like hell) and then, the Windows login dialog is a pretty secured window, by design – Simon Mourier Oct 20 '14 at 05:46
  • So I guess what I'm aiming to do is impossible then? – Kenneth Bautista Oct 20 '14 at 05:50

1 Answers1

0

I am going to go out on a limb here and say that simmon mourier is correct but assuming their is a way to do it I would try something like this to confirm that the window can not get returned at all.

This will return all child automation elements of whatever you pass into it.

    /// <summary>
    /// Returns all children elements of an automation element.
    /// </summary>
    public virtual List<AutomationElement> GetAllAutomationElements(AutomationElement aeElement)
    {
        AutomationElement aeFirstChild = TreeWalker.RawViewWalker.GetFirstChild(aeElement);

        List<AutomationElement> aeList = new List<AutomationElement>();
        aeList.Add(aeFirstChild);
        AutomationElement aeSibling = null;

        int count = 0;
        while ((aeSibling = TreeWalker.RawViewWalker.GetNextSibling(aeList[count])) != null)
        {
            aeList.Add(aeSibling);
            count++;
        }

        return aeList;
    }

Then spit the list out to a file or something so you can confirm after loging in what was actually available at the point when this ran.

Max Young
  • 1,522
  • 1
  • 16
  • 42
  • The problem is in `AutomationElement.RootElement.FindAll`. As Simmon said, IIS does not have a desktop to interact with. Anyway thanks for this tip though! – Kenneth Bautista Oct 20 '14 at 09:39