Solved

How can i enumerate all subfolders of a folder in registry in TreeView.

Posted on 2006-07-11
8
463 Views
Last Modified: 2010-04-05
Hi.

The title is self-explanatory.

I need to list in a treeview the subfolders (not the subfolders of the subfolders  (Depth=1)) of a path in registry.

Example : ( List SubFolders of    HKEY_USERS\Default )
------------------------------------------
HKEY Users
|->Default
      |-> AppEvents
      |-> Console
      |-> Control Panel
      |-> EHelp
      |-> Environment

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

Thanks in advance :)
0
Comment
Question by:CodedK
  • 3
  • 3
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 250 total points
ID: 17080321
Hi, here is how you can do it.

var
  Reg : TRegistry;
  s : TStringList;
begin
  Reg := TRegistry.Create;
  s := TStringList.Create;
  Reg.RootKey := HKEY_USERS;
  Reg.OpenKey('.DEFAULT', False);
  Reg.GetKeyNames(s);
  Memo1.Lines.Assign(s);
  s.Free;
  Reg.Free;
end;
0
 
LVL 28

Assisted Solution

by:ciuly
ciuly earned 250 total points
ID: 17080343
here is how to do it with ttreeview:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses registry;

procedure addthem(key:HKEY; path:string; treeview1:TTreeView);
var t:TTreeNode; r:tregistry; s:tstringlist; i:integer;
begin
  t:=TreeView1.Items.Add(TreeView1.Items.GetFirstNode,path);
  r:=tregistry.Create;
  r.RootKey:=key;
  if r.OpenKey(path,false) and r.HasSubKeys then
  begin
    s:=tstringlist.create;
    r.GetKeyNames(s);
    for i:=1 to s.count do
      TreeView1.Items.Addchild(t,s[i-1]);
    s.free;
  end;
  r.free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  addthem(HKEY_USERS,'.Default',TreeView1);
end;

end.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080351
Thanks :) ... both

Well if itsnt too much to ask do you know how can i filter those subfolders and list only those...
if they contain a subfolder named "2" ?
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17080381
After retrieving the list to stringlist you can simply check / search into it.
e..g
s.IndexOf('2'); // will return the index if found -1 otherwise.

OR

var
  Reg : TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_USERS;
  Reg.OpenKey('.DEFAULT', False);
  if Reg.KeyExists('2') then
     ShowMesasage('The key exists');
  Reg.Free;
end;
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 16

Author Comment

by:CodedK
ID: 17080398
Thanks :)

I'll split the points if you dont mind...
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17080404
That's fine.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17080603
Ciuly how can i insert those values to an allready existing item in the treeview ?
0
 
LVL 28

Expert Comment

by:ciuly
ID: 17080628

TreeView1.Items.Addchild(existing node,text)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now