Open In App

Build an Application to Search Installed Application using Python

Last Updated : 30 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to write python scripts to search for an installed application on Windows and bind it with the GUI application. We are using winapps modules for managing installed applications on Windows.

Prerequisite – Tkinter in Python

To install the module, run this command in your terminal:

pip install winapps

Below is what the GUI looks like as follows: 

Methods used  from winapps module

To print installed applications, the winapps module has winapps.list_installed() method. 

Python3




# import modules
import winapps
 
# get each application with list_installed()
for item in winapps.list_installed():
    print(item)


Output:

InstalledApplication(name=’Mi Smart Share’, version=’1.0.0.452′, install_date=None, install_location=None, install_source=None, modify_path=None, publisher=’Xiaomi Inc.’, uninstall_string=’C:\\Program Files\\MI\\AIoT\\MiShare\\1.0.0.452\\Uninstall.exe’)
 

InstalledApplication(name=’Git version 2.27.0′, version=’2.27.0′, install_date=datetime.date(2020, 7, 22), install_location=WindowsPath(‘D:/Installation_bulk/Git’), install_source=None, modify_path=None, publisher=’The Git Development Community’, uninstall_string='”D:\\Installation_bulk\\Git\\unins000.exe”‘)
 

InstalledApplication(name=’Microsoft 365 – en-us’, version=’16.0.13127.20408′, install_date=None, install_location=WindowsPath(‘C:/Program Files/Microsoft Office’), install_source=None, modify_path='”C:\\Program Files\\Common Files\\Microsoft Shared\\ClickToRun\\OfficeClickToRun.exe” scenario=repair platform=x64 culture=en-us’, publisher=’Microsoft Corporation’, uninstall_string='”C:\\Program Files\\Common Files\\Microsoft Shared\\ClickToRun\\OfficeClickToRun.exe” scenario=install scenariosubtype=ARP sourcetype=None productstoremove=O365HomePremRetail.16_en-us_x-none culture=en-us version.16=16.0′)
 

InstalledApplication(name=’On Screen Display Utility’, version=’1.0.0.140′, install_date=None, install_location=None, install_source=None, modify_path=None, publisher=’Xiaomi Inc.’, uninstall_string=’C:\\Program Files\\MI\\OSD Utility\\1.0.0.140\\Uninstall.exe’)
 

InstalledApplication(name=’Intel(R) Management Engine Components’, version=’1921.14.0.1280′, install_date=None, install_location=WindowsPath(‘C:/Program Files (x86)/Intel/Intel(R) Management Engine Components’), install_source=None, modify_path=None, publisher=’Intel Corporation’, uninstall_string='”C:\\ProgramData\\Intel\\Package Cache\\{1CEAC85D-2590-4760-800F-8DE5E91F3700}\\Setup.exe” -uninstall’)

………

For searching the existing applications, the module has search_installed(‘App_name’) method.

Python3




for item in winapps.search_installed('chrome'):
    print(item)


Output:

InstalledApplication(name=’Google Chrome’, version=’85.0.4183.102′, install_date=datetime.date(2020, 9, 11),
install_location=WindowsPath(‘C:/Program Files (x86)/Google/Chrome/Application’), install_source=None, 
modify_path=None, publisher=’Google LLC’, uninstall_string=’
“C:\\Program Files (x86)\\Google\\Chrome\\Application\\85.0.4183.102\\Installer\\setup.exe” 
–uninstall –system-level –verbose-logging’)

Searching application in windows using Tkinter

Python3




# import modules
from tkinter import *
import winapps
 
# function to attach output
def app():
 
    for item in winapps.search_installed(e.get()):
        name.set(item.name)
        version.set(item.version)
        Install_date.set(item.install_date)
        publisher.set(item.publisher)
        uninstall_string.set(item.uninstall_string)
 
 
# object of tkinter
# and background set for grey
master = Tk()
master.configure(bg='light grey')
 
# Variable Classes in tkinter
name = StringVar()
version = StringVar()
Install_date = StringVar()
publisher = StringVar()
uninstall_string = StringVar()
 
 
# Creating label for each information
# name using widget Label
Label(master, text="Enter App name : ",
      bg="light grey").grid(row=0, sticky=W)
Label(master, text="Name : ",
      bg="light grey").grid(row=2, sticky=W)
Label(master, text="Version :",
      bg="light grey").grid(row=3, sticky=W)
Label(master, text="Install date :",
      bg="light grey").grid(row=4, sticky=W)
Label(master, text="publisher :",
      bg="light grey").grid(row=5, sticky=W)
Label(master, text="Uninstall string :",
      bg="light grey").grid(row=6, sticky=W)
 
 
# Creating label for class variable
# name using widget Entry
Label(master, text="", textvariable=name,
      bg="light grey").grid(row=2, column=1, sticky=W)
Label(master, text="", textvariable=version,
      bg="light grey").grid(row=3, column=1, sticky=W)
Label(master, text="", textvariable=Install_date,
      bg="light grey").grid(row=4, column=1, sticky=W)
Label(master, text="", textvariable=publisher,
      bg="light grey").grid(row=5, column=1, sticky=W)
Label(master, text="", textvariable=uninstall_string,
      bg="light grey").grid(row=6, column=1, sticky=W)
 
 
e = Entry(master, width=30)
e.grid(row=0, column=1)
 
# creating a button using the widget
b = Button(master, text="Show", command=app, bg="Blue")
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5,)
 
mainloop()


Output:

 Code Explanation:

  1. The code starts by importing the modules that are needed for this program.
  2. The next line is a function called app() which will be used to run the main loop of the program.
  3. This function starts with a for loop that iterates through all of the items in winapps.search_installed().
  4. Each item has an attribute set, and then its name, version, install date, publisher, and uninstall string are all set accordingly.
  5. The last line creates an object called Analyze which contains all of these attributes as well as some other ones like how many times it was installed and when it was uninstalled last time.
  6. The code attempts to create a GUI that will allow the user to search for installed software on their computer.
  7. The code creates an object of tkinter and then imports winapps, which is a module that contains all of the information about installed software.
  8. The app() function is called when the GUI starts up and it iterates through each item in winapps.search_installed().
  9. It sets values for name, version, install_date, publisher, uninstall_string.
  10. The code starts by creating a master window with the name “master”.
  11. The background color of this window is set to grey.
  12. Next, we create three variables: name, version, and Install_date.
  13. These are all StringVar objects that store text values.
  14. The next line creates a Label widget on the master window with the text “Enter App Name :” in light grey as its background color.
  15. This label will be placed at row 0 and will have sticky w’s enabled so it can’t move from its position when you drag it around using your mouse pointer.
  16. Next, two more labels are created for each variable: one for displaying their names (label named “name”) and one for displaying their versions (label named “version”).
  17. They’re both placed at row 2 because they need to be above the first label which displays Enter App Name : .
  18. Sticky w’s are also enabled here so they won’t move out of place when you drag them around using your mouse pointer either.
  19. Finally, a fourth label is created called Install Date which has a light grey background color like all other labels in this program except for the last one which has no background color specified yet but instead uses an implicit default value of white since there
  20. The code is a tkinter script that creates labels on the master window.
  21. The code starts by creating a widget called Entry.
  22. The widget is created with the master and width properties set to 30.
  23. Next, the code creates a label for class variable name using widget Entry.
  24. Label(master, text=””, textvariable=name, bg=”light grey”).grid(row=2, column=1, sticky=W) creates a label that will be placed in row 2 of column 1 on the master window.
  25. The text variable is set to “”.
  26. This means that there will be no text displayed on this label because it has been given an empty string as its value for its textvariable property (textvariable).
  27. The next line of code creates another label for class variable version using widget Entry.
  28. Label(master, text=””, textvariable=version, bg=”light grey”).grid(row=3, column=1, sticky=W) creates another label that will be placed in row 3 of column 1 on the master window.
  29. The text variable is set to “”.
  30. This means that there will be no text displayed on this label because it has been given an empty string as its value for its textvariable property (textvariable).
  31. The code is the most basic example of a widget.
  32. The code creates a label for class variable name using widget Entry.
  33. The master is the parent widget and textvariable=name is the child widget.
  34. The bg=”light grey” parameter sets the background color to light grey.
  35. The grid() function arranges widgets in rows and columns, with row=2, column=1, and sticky=W as shown above.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads