Is There A Way To Find The Path Of An Application With Standard Libraries?
I'd like to know if it is possible to find the installation directory of an application under Windows 7, such as MS Excel, with standard python 2.7 libraries. I mean, it shouldn't
Solution 1:
It might be quite tricky, however one approach would be to search for the launcher exe location in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\foo.exe
Thusly something like this (I do not have Windows on this computer, so edits are welcome if bugs found ;), code should be Python 2 and 3 compatible):
try:
import winreg
except ImportError:
import _winreg as winreg
handle = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe")
num_values = winreg.QueryInfoKey(handle)[1]
for i in range(num_values):
print(winreg.EnumValue(handle, i))
On Python 2 the module is named _winreg
, but winreg
on Python 3.
Post a Comment for "Is There A Way To Find The Path Of An Application With Standard Libraries?"