Python winreg looping through sub-keys

前端 未结 6 1386
悲哀的现实
悲哀的现实 2021-01-12 05:16

I\'m able to successfully retrieve the 5 sub-keys from my windows 7 machine registry hive \"HKEY_LOCAL_MACHINE\" with the code below.

from _winreg import *

         


        
6条回答
  •  逝去的感伤
    2021-01-12 05:29

    For iterating through keys of Windows registry, you would need EnumKey() from _winreg module. Given below is the definition for EnumKey() :-

    def EnumKey(key, index):

    • Enumerates subkeys of an open registry key.
    • key is an already open key, or any one of the predefined HKEY_* constants.
    • index is an integer that identifies the index of the key to retrieve.

    Note that this method, takes index as an argument, and will provide you the key only for the given index. Therefore, in order to get all the keys, you need to increment the index by one and continue until you encounter WindowsError.

    Refer to this post for a detailed understanding on the same. The Github link for the code can be found in the post.

提交回复
热议问题