Getting All Process Names, Window Titles, Window Classes and Handles regardless of Window State

Hey Everyone!

TLDR dude: I need to obtain all window titles regardless of whether they are active, minimized, hidden, in another dimension, whatever. If there are multiple instances of windows with the same title I want the workflow to either terminate or force the user select the window they want the bot to attach to. Just looking for something simple that works inside an “invoke code” activity (or other option) that can capture ALL window titles. That’s it. Because I know this will be asked: No I cannot have the bot just open a new instance of this window and attach to it to perform x, y, z. No, I can’t kill all processes in question and open a new instance and perform a, b, c. If you know how to do this, read no further.

Background:
I’ve finished building a bot that automates an application with semi-exposed Chromium containers. The way the bot works is a user opens one of these windows then runs the bot which utilizes the “attach window” activity.

There can multiple instances of these windows open with the same selectors (app and cls) but it’s the “title” that helps the bot distinguish between them. However, I can already foresee cases where users will have multiple windows open where the “title” is the same too.

It’s my wishful assumption that when confronted with windows with identical selectors UIPath uses the last active instance, which would probably be fine in most scenarios. Problem is, I’d rather not have the bot operate off this assumption. And any additional selectors beyond app, cls and title are irrelevant.

I’ve tried using the “System.Diagnostics.Process inside a for each process in processes loop activity” shtick. While this does return all running process names and some window titles… It doesn’t do so for the type of window in question unless it’s in the foreground and/or activated.

I figured the next best option would be to use the “invoke code” or “invoke powershell” activity. There are some vba/powershell examples I have found that accomplish what I need like:

here and here

But there’s got to be a way to accomplish this without invoking a wall of code or venturing down the “escape quote” rabbit hole of invoking the powershell script, no?

Hi @tSingularity20XX

Welcome to UiPath forum.

The Attach Window activity has an output property ApplicationWindow which can be assigned a variable to uniquely identify the window. Using the variable to perform actions like maximize, minimize, close windows, etc.

Hm, yes I thought about it from this direction as well. But if you have two window instances with the same selectors and UIPath assigns a variable to one, it won’t necessarily be the correct instance that needs to be interacted with. I would somehow need a way to count the number of instances of windows with duplicate selectors (title) if they exist.

Hi @tSingularity20XX

Have you tried the non-greedy selectors. Please see the reference documentation. Adding a idx=‘1’ for first active window, idx=‘2’ for second active window, etc.

My suggestion is to have a element exist activity where the idx=‘{{idxvalue}}’ idxvalue is a string variable where you can increment by 1 (convert to int32 and back to string) each time and count the number of window with duplicate selectors. The Timeout (milliseconds) should be reduced to (maybe 500) for element exist. Then wrapped the related activities around a Do While loop to exit the do while when the element exist activity returns false.

1 Like

This worked like a charm! Thanks for the help!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.