What is winreg.EnumKey in Python?
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
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.
Syntax
winreg.EnumKey(key, index)
Parameters
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.
Return value
The method returns a string containing the subkey.
Code
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
Copyright ©2026 Educative, Inc. All rights reserved