I'm trying to get the installation dir of every application installed in my system , then I will store those dir in notepad or anywhere then access that. so basically I want to build a python app like cortana which open any application installed in my system and open it. so this what I thought of
- get path of installation from reg with help of winreg
- then store it
- then access it with other py program that take input of application name and search in that file copy the whole path of that specific application then send it to a python file which has os.open and application start .
and i will store data in sqllite3 or txt file .
the below code doesnt display anything
import winreg
def app(hive, flag):
areg=winreg.ConnectRegistry(None,hive)
akey=winreg.OpenKey(areg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
0, winreg.KEY_READ | flag)
subkey=winreg.QueryInfoKey(akey)[0]
soft_list=[]
for i in range(subkey):
soft={}
try:
soft['path']=winreg.QueryValueEx(subkey, "InstallSource")[0]
except:
soft['path']="null"
soft_list.append(soft)
return soft_list
soft_list = app(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY) + app(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_64KEY) + app(winreg.HKEY_CURRENT_USER, 0)
for software in soft_list:
print (software['path'])
print(len(soft_list))
this below code works idk y but it dont display all application
import winreg
def foo(hive, flag):
aReg = winreg.ConnectRegistry(None, hive)
aKey = winreg.OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
0, winreg.KEY_READ | flag)
count_subkey = winreg.QueryInfoKey(aKey)[0]
software_list = []
for i in range(count_subkey):
software = {}
try:
asubkey_name = winreg.EnumKey(aKey, i)
asubkey = winreg.OpenKey(aKey, asubkey_name)
software['name'] = winreg.QueryValueEx(asubkey, "DisplayName")[0]
try:
software['i']=winreg.QueryValueEx(asubkey,"InstallSource")[0]
except EnvironmentError:
software['i'] = winreg.QueryValueEx(asubkey, "InstallSource")[0]
software_list.append(software)
except EnvironmentError:
continue
return software_list
software_list = foo(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY) + foo(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_64KEY) + foo(winreg.HKEY_CURRENT_USER, 0)
for software in software_list:
print (software['name'], software['i'])
print('Number of installed apps: %s' % len(software_list))
and this code below display all application(352 app) but when i add for path the code dont display all application(205)
import winreg
def foo(hive, flag):
aReg = winreg.ConnectRegistry(None, hive)
aKey = winreg.OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
0, winreg.KEY_READ | flag)
count_subkey = winreg.QueryInfoKey(aKey)[0]
software_list = []
for i in range(count_subkey):
software = {}
try:
asubkey_name = winreg.EnumKey(aKey, i)
asubkey = winreg.OpenKey(aKey, asubkey_name)
software['name'] = winreg.QueryValueEx(asubkey, "DisplayName")[0]
software_list.append(software)
except EnvironmentError:
continue
return software_list
software_list = foo(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY) + foo(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_64KEY) + foo(winreg.HKEY_CURRENT_USER,0)
for software in software_list:
print (software['name'])
print('Number of installed apps: %s' % len(software_list))
There's no good answer for your question. You won't find all install paths from registry. Also,
InstallSource
would not be the installed path, but it's source, and is often missing.Btw, I wrote a package that does what you coded above, called
windows_tools.installed_software
From my experience, there's no good way to list all installed programs under windows. You might need to combine various sources, like WMI, registry and perhaps walking over
program files
andprogram files (x86)
One way to get the data via WMI:
Good luck.