winreg
(Windows Registry API) provides functions to expose the Windows Registry API to Python. We use this module to expose a low-level interface to the registry.
EnumKey
enumerates all the subkeys of a specified registry key. Whenever this method is called, it only returns one subkey. To return multiple subkeys, the method needs to be called repeatedly. When there are no subkeys left, the method raises an OSError
exception.
winreg.EnumKey(key, index)
Key
: Already open key. It can also be one of the predefined HKEY_*
constants.
index
: Integer value. Refers to the index of the key we want to retrieve.
The method returns a string containing the subkey.
Here is a coding example to understand the enumeration used to loop for an existing key:
// open a key using OpenKey() method.
key = OpenKey()
// run a for loop
for i in range(1024):
try:
keynames = winreg.EnumKey(key, i)
print(keynames)
except:
pass
Free Resources