0

I am making a program that will be able to open programs such as discord, google chrome, epic games launcher, steam, etc. How would I go about finding where the programs are installed on the device (Windows 10). I have done a bit of research and there is a thing called the Windows registry but I don't know how to make it so you can get the .exe file to launch the program.

from tkinter import *


def WindowCentre():
    positionRight = int(Main.winfo_screenwidth() / 2 - 960 / 2)
    positionDown = int(Main.winfo_screenheight() / 2 - 540 / 2)
    Main.geometry("+{}+{}".format(positionRight, positionDown))


def ButtonClick(Application):
    # Whatever the code is for here

    # pass is just for the error
    pass


Main = Tk()
Main.title("Program Launcher")
# Main.iconbitmap("")
Main.configure(bg="#2c2f33")
Main.geometry("960x540")
WindowCentre()

DiscordImage = PhotoImage(file="Images/Discord Icon.png")
DiscordButton = Button(image=DiscordImage, activebackground="#2c2f33", 
                       activeforeground="#2c2f33", bg="#2c2f33",
                       width=150, height=150, borderwidth=0,
                       command=lambda: ButtonClick("Discord"))
DiscordButton.grid(row=0, column=0, padx=10, pady=10)

EpicGamesImage = PhotoImage(file="Images/Epic Games Launcher Icon.png")
EpicGamesButton = Button(image=EpicGamesImage, activebackground="#2c2f33", 
                         activeforeground="#2c2f33", bg="#2c2f33",
                         width=150, height=150, borderwidth=0,
                         command=lambda: ButtonClick("Epic Games Launcher"))
EpicGamesButton.grid(row=0, column=1, padx=10, pady=10)

Main.mainloop()

So how can I make the program find where the program is installed on any windows device and then make a button on the gui open it when clicked? I could just use default directory but most programs have the option to change install location, so I am looking for a method of finding the programs install location.

Thanks for anyones help!

EDIT

I was wondering if this would work with launching the program? Windowsapps finds the AppID of the exe. I don't know how to use this to launch the program, can anyone help make sense of it?

import windowsapps

name, appid = windowsapps.find_app('Discord')
#searches for the APPLICATION NAME and returns:-
#name = Name of the application.
#appid = AppId of the application

print(name)
print(appid)
  • You might want to do some research first which might get you to threads such as [this one](https://stackoverflow.com/questions/26346078/how-to-get-in-python-the-path-to-a-installed-program-in-windows), [this one](https://stackoverflow.com/questions/18044937/is-there-a-way-to-find-the-path-of-an-application-with-standard-libraries) and [this one](https://stackoverflow.com/questions/21090325/python-look-into-the-registry-to-find-install-location-of-a-program). – metatoaster May 31 '21 at 02:02
  • If you install those applications using their installers, then their paths to the executables should be added into the PATH environment variable. You can then just use the executable name without the full path to execute the application. – acw1668 May 31 '21 at 05:38
  • Does [this post](https://stackoverflow.com/questions/1724693/find-a-file-in-python) help? – typedecker Mar 01 '22 at 14:26

2 Answers2

0

You will be able to find the files by os.walk function

for root, dirs, files in os.walk(appLocation + appFolder):
    for name in files:
        if name.endswith(("lib", ".so")):
            os.path.join(root, name)

you will be able to find the exe you want with this method and you can get into the installed location by os.path.join

It is well documented here http://docs.python.org/3/library/os.html#os.walk,

  • Im sorry I dont know how to use this in the program. How and where does it go? – Edward Nivison May 31 '21 at 02:36
  • Well then, I do not understand what you want, please describe it a bit more briefly – Dhruv Chaturvedi May 31 '21 at 03:01
  • I was wanting to be able to find the installed program's executable. All I need is the location of the .exe file and then I can just use this to launch the program.`os.system('"%s"' % ApplicationLaunch)` – Edward Nivison May 31 '21 at 06:34
  • @EdwardNivison I am pretty sure that with `walk` You can find the location of the exe, also there is an option to let the user decide which exe to launch and then save that path for later reference – Matiiss May 31 '21 at 09:16
-1

How would I go about finding where the programs are installed on the device (Windows 10).

In order to find the path of the application you have to go through the start menu and look for the desired application.

In the start menu, right click on the application -> more -> open file location

Left click on that, and you will be taken to Windows/Start Menu/Programs folder somewhere in Drive C:// Where you will find the shortcut for that application.

Copy the target path of the application by right clicking it on the properties. For Eg. If I want to open Visual Studio Code:

codePath = "C:/Users/kanis/AppData/Local/Programs/Microsoft VS Code/Code.exe" (path of VSCode start menu application shortcut in my PC)

Then, os.startfile(codePath). Python will run and open the req. application (VSCode in this case) for you.

Dharman
  • 30,962
  • 25
  • 85
  • 135
kxnyshk
  • 167
  • 2
  • 9
  • The OP wants a way to programmatically find the address, this is more of a manual search for the address, which is not possible for dynamic situations. – typedecker Mar 01 '22 at 13:02
  • This is just the location on YOUR computer. As stated by OP, since most programs have the option to change install location, OP is looking for a more dynamic method of finding the programs install location. – Bao Huynh Lam Mar 01 '22 at 14:55
  • 1
    @typedecker oh okay I see. Sorry! I guess I misanalysed the question by OP. I was recetly working on a python script to open certain desktop applications via voice commands, used this method there.. – kxnyshk Mar 01 '22 at 16:02