Re: list registry keys


[ Related Articles and Replies ] [ DelphiLand FAQ ] [ Delphi Tutorials ]

Posted by WAllison on May 10, 2002 at 17:18:20:

In Reply to: list registry keys posted by Stefan Loeners P12167 on May 06, 2002 at 21:12:55:

: How would I get a list of all registry keys and their values? I need for example all keys (and subkeys) under HKEY_LOCAL_MACHINE \ Software. In other words, what would a recursive search in the registry look like?

------------------------

procedure BuildRegistry;
var AReg: TRegistry;
    RegKeyInfo: TRegKeyInfo;
    KeyCount: integer;
    KeyNames, ValueNames: TStringList;
    TreeNode: TTreeNode;
    KeyName: string;
 procedure DoKey(Key, DisplayName: string; Node: TTreeNode);
 var KeyNames, ValueNames: TStringList;
     KeyCount: integer;
     SubTreeNode: TTreeNode;
     RInfo: TRegKeyInfo;
 begin
  KeyNames := TStringList.Create;
  ValueNames := TStringList.Create;
  infobox.Items.Add(Key);
  AReg.OpenKey(Key ,False);
  AReg.GetKeyNames(KeyNames);
  AReg.GetValueNames(ValueNames);
  AReg.GetKeyInfo(RInfo);
  SubTreeNode := KeyTreeView.Items.AddChild(Node, DisplayName);
  for KeyCount := 0 to RInfo.NumSubKeys-1 do
   begin
    If AReg.KeyExists(Key+KeyNames[KeyCount]+'\') then
     DoKey(Key+KeyNames[KeyCount]+'\',KeyNames[KeyCount], SubTreeNode);
   end;
  //Process Values here - same sort of thing as the keys
  if KeyNames <> nil then KeyNames.Free;
  if ValueNames <> nil then ValueNames.Free;
 end;
begin
  AReg := TRegistry.Create;
  AReg.RootKey := HKEY_CURRENT_USER;
  AReg.OpenKey('', False);
  AReg.GetKeyInfo(RegKeyInfo);
  TreeNode := KeyTreeView.Items.Add(nil, 'HKEY_CURRENT_USER');
  KeyNames := TStringList.Create;
  ValueNames := TStringList.Create;
  AReg.GetKeyNames(KeyNames);
  AReg.GetValueNames(ValueNames);
  KeyName := '\';
  for KeyCount := 0 to RegKeyInfo.NumSubKeys-1 do
   begin
    DoKey(KeyName+KeyNames[KeyCount]+'\', KeyNames[KeyCount], TreeNode);
   end;
  if KeyNames <> nil then KeyNames.Free;
  if ValueNames <> nil then ValueNames.Free;
  if AReg <> nil then AReg.Free;
end;

Hope this helps

Waz


Related Articles and Replies:


[ Related Articles and Replies ] [ DelphiLand FAQ ] [ Delphi Tutorials ]