Accessing the Taskbar icons

  • Thread starter Krishnan Shankar
  • Start date
K

Krishnan Shankar

Hi All,

I am automating an application in windows using python.

After installation i need to check if the applications icon has appeared in
Taskbar or not. If yes i need to right click the application.

I had been using pywinauto for the same but could not get the job done till
now.

I did the following,

app=pywinauto.application.Application()
hand=pywinauto.findwindows.find_windows(class='Shell_TrayWnd', title=u'')

When i use the handler, get the window and do a right click i am able to
click only in the taskbar and not icons. That maybe because i did not
recognise the icon yet.

Can you guide me how to do the same using pywinauto or pywin32?

Regards,
Krishnan
 
Joined
Apr 8, 2024
Messages
1
Reaction score
0
Hi All,

I am automating an application in windows using python.

After installation i need to check if the applications icon has appeared in
Taskbar or not. If yes i need to right click the application.

I had been using pywinauto for the same but could not get the job done till
now.

I did the following,

app=pywinauto.application.Application()
hand=pywinauto.findwindows.find_windows(class='Shell_TrayWnd', title=u'')

When i use the handler, get the window and do a right click i am able to
click only in the taskbar and not icons. That maybe because i did not
recognise the icon yet.

Can you guide me how to do the same using pywinauto or pywin32?

Regards,
Krishnan


By using pywin2. You can get program names/application names in the taskbar

import win32gui # Import the windows API for getting open apps

apps = set() # Use a set to avoid duplicate app names
ignoredApps = ['ABC'] # Any apps you want to exclude (such as built-in apps or extra windows such as paint.net windows) go here, or leave the list empty

def getWindows(hwnd, *args) -> list: # This returns always returns a list, and it takes in a hwnd argument and multiple other arguments to be ignored.
global apps

if win32gui.IsWindowVisible(hwnd):
title = win32gui.GetWindowText(hwnd) # Gets title
if title and not any(ignore_app in title for ignore_app in ignoredApps): # To ensure the title of the program is not blank and doesn't contain any ignored apps
split_title = title.rsplit('-', 1)
if len(split_title) == 2:
app_name = split_title[1].strip() # Extract app name from full window title
if app_name: # Ensure app name is not empty
apps.add(app_name) # Add app name to the set

win32gui.EnumWindows(getWindows, '') # Call the function with hwnd argument filled
print(apps) # Print the set of unique app names, excluding any apps in ignoredApps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,794
Messages
2,569,641
Members
45,355
Latest member
SJLChristi

Latest Threads

Top