0

I am not able to get any "title bar" object of a window via UI automation client. Here the Powershell demo code I am using, but the result is always empty. Even if I list all child-elements of a CMD-window it shows all other elements, but not the title bar. What is wrong here?

Add-Type -AssemblyName 'UIAutomationClient'
$cTrue = [Windows.Automation.PropertyCondition]::TrueCondition
$root = [Windows.Automation.AutomationElement]::RootElement
$cmd  = $root.FindAll("Children", $cTrue).where{$_.current.name -eq 'Command Prompt'}

$bar  = [System.Windows.Automation.ControlType]::TitleBar
$prop = [System.Windows.Automation.AutomationElement]::ControlTypeProperty
$cond = [System.Windows.Automation.PropertyCondition]::new($prop, $bar)
$cmd.FindFirst("Children", $cond)
Carsten
  • 1,612
  • 14
  • 21
  • Works for me provided I change the `.where` to a `| Where-Object { ... }` I tested using notepad but I doubt that changes anything – patthoyts May 31 '23 at 11:26
  • Are you getting some details of that object or just no error? I tested that code in latest Win11 and I dont get the title bar object back. Even if I try $cTrue as an unfiltered condition in last line. – Carsten May 31 '23 at 11:31
  • 1
    I can list the titlebar properties. `> $tb.current.Name Untitled - Notepad` – patthoyts May 31 '23 at 11:42
  • The .NET UIAutomationClient API uses outdated UIA version 2, which is known to have issues with newer applications. I get best results using UIA version 3, which is a native API, so you need a wrapper library to use in .NET languages like PowerShell. See [example using FlaUI](https://stackoverflow.com/a/73541499/7571258). – zett42 May 31 '23 at 13:51
  • @patthoyts That is the name of the window, but not the titlebar-object (even if it is the same content in this sample). – Carsten Aug 02 '23 at 10:39

0 Answers0