?
Solved

How to iterate and get all the keys and subkeys in a registry in Delphi 6?

Posted on 2008-11-17
3
Medium Priority
?
1,108 Views
Last Modified: 2012-05-05
How to iterate and get all the keys and subkeys in a registry in Delphi 6?
0
Comment
Question by:sepknow
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
ThievingSix earned 1000 total points
ID: 22982719
The below code should work fine. But loading all the registry keys at one time will be processor intensive and take a long time, even with threading(although this would help). Your best solution would be to load the first sub level of keys and if a user clicks on one to go down you would then get those new keys.
procedure GetRegistryKeys(const ROOTKEY: HKEY; const InList: TStrings; const StartKey: String = '');
var
  Reg : TRegistry;
  I : Integer;
  NameList : TStringList;
begin
  Reg := TRegistry.Create;
  Try
    Reg.RootKey := ROOTKEY;
    If Reg.OpenKeyReadOnly(StartKey) Then
      begin
      NameList := TStringList.Create;
      Try
        Reg.GetKeyNames(NameList);
        For I := 0 To NameList.Count - 1 Do
          begin
          InList.Add(StartKey + '\' + NameList.Strings[I]);
          GetRegistryKeys(ROOTKEY,InList,StartKey + '\' + NameList.Strings[I]);
        end;
      Finally
        NameList.Free;
      end;
    end;
  Finally
    Reg.Free;
  end;
end;
 
procedure TForm12.Button1Click(Sender: TObject);
var
  RegistryKeys : TStringList;
begin
  RegistryKeys := TStringList.Create;
  RegistryKeys.BeginUpdate;
  GetRegistryKeys(HKEY_USERS,RegistryKeys);
  RegistryKeys.EndUpdate;
  ListBox1.Items.BeginUpdate;
  ListBox1.Items.Assign(RegistryKeys);
  ListBox1.Items.EndUpdate;
  RegistryKeys.Free;
end;

Open in new window

0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 1000 total points
ID: 22982721
use the registry unit


uses Registry;
 
procedure TForm1.ListKeys(BaseKey: string; List: TStrings);
var Reg: TRegistry;
  procedure AddSubKeys(KeyName: string);
  var KeyNames: TStrings;
    I: Integer;
  begin
    List.Add(KeyName);
    KeyNames := TStringList.Create;
    try
      if Reg.OpenKey(KeyName, False) then
      try
        Reg.GetKeyNames(KeyNames);
      finally
        Reg.CloseKey;
      end;
      for I := 0 to KeyNames.Count - 1 do
        AddSubKeys(KeyName + '\' + KeyNames[I]);
    finally
      FreeAndNil(KeyNames);
    end;
  end;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    AddSubKeys(BaseKey);
  finally
    FreeAndNil(Reg);
  end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ListKeys(Edit1.Text, Memo1.Lines);
end;

Open in new window

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 22982726
ThievingSix,
oops forgot to refresh
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question