Desktop.Instance.Windows() throws ArgumentException

Apr 16, 2012 at 7:11 AM



I am trying to get all windows on desktop using Desktop.Instance.Windows() but it throws ArgumentException - Value does not fall within expected range.

(But there is no argument being passed  :S )

I tried taking the UIAutoamtion path-

                AutomationElement rootElement = AutomationElement.RootElement;
                var j = rootElement.FindAll(TreeScope.Subtree, Condition.TrueCondition);

FindAll throws the same exception.

What is the recommended approach for getting all windows.

Please let me know workarounds too.

Many Thanks!

Apr 18, 2012 at 7:26 AM

Update: It fails only when I debug in VS2010, not when I launch the output .exe from cmd prompt. Not much of an issue. Thanks.