Fuzzyman wrote:
Does anyone know how to use _winreg to get path information (location
of install) for all versions of Python installed (and also which is the
most recent) ?
This should probably work:
import _winreg
def get_subkey_name s(reg_key):
index = 0
L = []
while True:
try:
name = _winreg.EnumKey (reg_key, index)
except EnvironmentErro r:
break
index += 1
L.append(name)
return L
def function_in_sea rch_of_a_name() :
"""
Return a list with info about installed versions of Python.
Each version in the list is represented as a tuple with 3 items:
0 A long integer giving when the key for this version was last
modified as 100's of nanoseconds since Jan 1, 1600.
1 A string with major and minor version number e.g '2.4'.
2 A string of the absolute path to the installation directory.
"""
python_path = r'software\pyth on\pythoncore'
L = []
for reg_hive in (_winreg.HKEY_L OCAL_MACHINE,
_winreg.HKEY_CU RRENT_USER):
try:
python_key = _winreg.OpenKey (reg_hive, python_path)
except EnvironmentErro r:
continue
for version_name in get_subkey_name s(python_key):
key = _winreg.OpenKey (python_key, version_name)
modification_da te = _winreg.QueryIn foKey(key)[2]
install_path = _winreg.QueryVa lue(key, 'installpath')
L.append((modif ication_date, version_name, install_path))
return L