I prefer to avoid mistakes instead of diving right into it ...
Use _winreg.QueryInfoKey to get the number of values:
import _winreg key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r'PATH\TO\KEY', 0, _winreg.KEY_READ) for i in xrange(0, _winreg.QueryInfoKey(key)[1]): print _winreg.EnumValue(key, i)
To get the number of keys, the same method, another index (second half of the original question):
for i in xrange(0, _winreg.QueryInfoKey(key)[0]): print _winreg.EnumKey(key, i)
Note: use import instead of from ... import to make it explicit where the functions and variables come from. Itβs easier to follow the code in the future.
Vertigoray
source share