Python has a module to access the Windows registry. It comes together in the default library, you do not have to import anything external.
import winreg
This module has a function that receives a HKEY and an index, and returns the name of the HKEY subkey at that index. If the index is invalid, it releases a WindowsError. Thus it is possible to get the name of all the immediate subkeys of a given HKEY.
def obter_subchaves_imediatas(hkey):
i = 0
try:
while True:
yield winreg.EnumKey(hkey, i)
i += 1
except WindowsError:
pass
Now, using the above function, it is easy to write a routine that recursively navigates through the records tree. It's basically the pre-order navigation algorithm in any tree.
def navegar_arvore(nome_chave_raiz):
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, nome_chave_raiz)
for nome_subchave in obter_subchaves_imediatas(hkey):
nome_completo = f'{nome_chave_raiz}\{nome_subchave}'
yield nome_completo
yield from navegar_arvore(nome_completo)
A simple loop lets you get all paths from a certain root.
for chave in navegar_arvore('Control Panel'):
print(chave)
There are several points that can be improved in this code, but what was shown here is sufficient to solve the problem.