Solved

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

Posted on 2006-07-11
8
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:2266180
2266180 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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:2266180
ID: 17080628

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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