The logically next step, after we started searching for a control using a wildcard, is to get a window by part of its name.
Task: use UIAutomation to get a window by a fragment of its name.
Requirements: demonstrate how to use the technique.
Solution: code that is needed is as simple as it can be:
Set-StrictMode -Version Latest; ipmo [path]\UIAutomation.dll; Start-Process calc; Get-UIAWindow -Name *alc*r
After we started the calc process, all the lines of code below will work:
Set-StrictMode -Version Latest; ipmo [path]\UIAutomation.dll; Start-Process calc; Get-UIAWindow -Name *alc*r Get-UIAWindow -Name Calc* Get-UIAWindow -Name CA?culator Get-UIAWindow -pn calc Get-UIAWindow -pid (Start-Process calc -PassThru).Id Start-Process calc -PassThru | Get-UIAWindow
There should be placed a note: whereas the asterisk ‘*’ is a replacement for anything including an empty place, the question mark ‘?’ requires that something non-empty was under the sign. I.e., the following replacements are right:
However, Cal?culator is not right. Ca?culator or Cal?ulator both are right.