Announcement

Collapse
No announcement yet.

Get Sub-keys and Values for a Register Key

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get Sub-keys and Values for a Register Key

    Please use the script to get sub-keys and values of a valid register-key

    Code:
    import _winreg
    
    def main():
        ## Pass the here at "key" variable
        key = r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft'
        hekey = key.split('\\')[0]
        hkey = getattr(_winreg, hekey)
        skey = '\\'.join(key.split('\\')[1:])
        try:
            pkey = _winreg.OpenKey(hkey, skey)
            print 'Given Key: '+hekey+'\\'+skey
            try:
                print 'Sub Keys: '
                print('-'*25)
                i=0
                while True:
                    print _winreg.EnumKey(pkey, i)
                    i += 1
            except WindowsError as e:
                pass
            finally:
                try:
                    print 'Values: '
                    print('-'*25)
                    j=0
                    while True:
                        sep = ''
                        for k in list(_winreg.EnumValue(pkey, j)):
                            sep = sep+str(k)+'\t'
                        print sep
                        j += 1
                except WindowsError as e:
                    pass
        except WindowsError as e:
            print 'Check whether '+hekey+'\\'+skey+' is valid or accessible!'
            
    if __name__ == '__main__':
        main()
    Sample Output:
    Click image for larger version

Name:	Get Sub-keys and Values for a Register Key.PNG
Views:	1
Size:	21.3 KB
ID:	4777

    Last edited by Purushothaman; 11-04-2016, 01:28 PM.
Working...
X