def list_path(key, path): count = 0 (num_subkeys, max_subkeylen, max_classlen) = conn.QueryInfoKey(key, winreg.String())[1:4] for i in range(num_subkeys): name = winreg.StringBuf() name.size = max_subkeylen+2 # utf16 0-terminator keyclass = winreg.StringBuf() keyclass.size = max_classlen+2 # utf16 0-terminator (name, _, _) = conn.EnumKey(key, i, name, keyclass=keyclass, last_changed_time=None) name2 = winreg.String() name2.name = name.name subkey = conn.OpenKey(key, name2, 0, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) count += list_path(subkey, "%s\\%s" % (path, name)) list_values(subkey) return count
def list_values(key): (num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:8] for i in range(num_values): name = winreg.StringBuf() name.size = max_valnamelen (name, type, data, _, data_len) = conn.EnumValue(key, i, name, 0, "", max_valbufsize, 0) print "\ttype=%-30s size=%4d '%s'" % type, len, name if type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ): print "\t\t'%s'" % data
def list_values(key): (num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:7] for i in range(num_values): name = winreg.ValNameBuf() name.size = max_valnamelen (name, type, data, _, data_len) = conn.EnumValue(key, i, name, 0, [], max_valbufsize, 0) print("\ttype=%-30s size=%4d '%s'" % (type, name.size, name)) if type in (misc.REG_SZ, misc.REG_EXPAND_SZ): print("\t\t'%s'" % data)
def test_getkeyinfo(self): handle = self.conn.OpenHKLM( None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) x = self.conn.QueryInfoKey(handle, winreg.String()) self.assertEqual(9, len(x)) # should return a 9-tuple self.conn.CloseKey(handle)
(name, _, _) = conn.EnumKey(key, i, name, keyclass=keyclass, last_changed_time=None) name2 = winreg.String() name2.name = name.name subkey = conn.OpenKey(key, name2, 0, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) count += list_path(subkey, "%s\\%s" % (path, name)) list_values(subkey) return count if len(args) > 1: root = args[1] else: root = "HKLM" if opts.createkey: name = winreg.String() name.name = "SOFTWARE" # Just sample code, "HKLM\SOFTWARE" should already exist root = conn.OpenHKLM( None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) conn.CreateKey( root, name, keyclass=winreg.String(), options=0, access_mask=0, secdesc=None, action_taken=0) else: