Results 1 to 3 of 3

Thread: Recursive Registry

  1. #1

    Recursive Registry

    Hello,

    Maybe this is not so related with games, but it can be used as debugging tools.

    Anyone can show me some code to output registry tree and its value ?

    I got this code somewhere:

    Code:
    function readTree(rootKey: HKEY; startKey: string): TStringList;
    var reg: TRegistry;
    childKeys, valueList: TStringList;
    i: integer;
    begin
      childKeys:=TStringList.Create;
      valueList:=TStringList.Create;
      result:=TStringList.Create;
    
      reg:=TRegistry.Create;
      reg.RootKey:=rootKey;
      reg.OpenKey(startKey, false);
    
      reg.GetKeyNames(childKeys);
      reg.GetValueNames(valueList);
    
      result.AddStrings(valueList);
    
      for i:=0 to childKeys.count-1 do begin
              result.AddStrings(readTree(rootKey, startKey + '\' + childKeys[i]));
      end;
    end;
    Usage:
    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      memo1.Text := readTree(HKEY_CURRENT_USER, '\Software\MySoftware\').Text;
    end;
    But it did not print the path and value.

    Please if anyone can help me, I am stuck with this for 2 days now

    Thanks.

  2. #2

    Recursive Registry

    You are leaking memory all over the place.
    This code should work, although I don't know if this is exactly what you wanted:

    Code:
    uses Registry;
    
    procedure readTree(List: TStrings; rootKey: HKEY; const startKey: string);
    var
      reg: TRegistry;
      childKeys, valueList: TStringList;
      i: integer;
    begin
      childKeys := TStringList.Create;
      valueList := TStringList.Create;
      reg := TRegistry.Create;
      try
        reg.RootKey:=rootKey;
        reg.OpenKey(startKey, false);
    
        reg.GetKeyNames(childKeys);
        reg.GetValueNames(valueList);
        for i := 0 to valueList.Count-1 do
          List.Add(startKey + valueList[i]);
    
        for i:=0 to childKeys.count-1 do
           readTree(List, rootKey, startKey + '\' + childKeys[i]);
      finally
        childKeys.Free;
        valueList.Free;
        reg.Free;
      end;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with Memo1 do
      begin
        Lines.BeginUpdate;
        Lines.Clear;
        readTree(Memo1.Lines, HKEY_CURRENT_USER, 'Software');
        Lines.EndUpdate;
      end;
    end;

  3. #3

    Recursive Registry

    Thanks siim,

    This is very useful for diagnostic things. I dont know, sometimes got a complaint from user that the game does not work anymore. After I checked, the registry settings was messed up.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •