Solved

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

Posted on 2006-07-11
8
469 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: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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange behavior when a form is closed 6 57
Unique identifier on a terminal server (rdp) 4 54
how can i search if string exist in array ? 3 59
DBGrid or StringGrid ? 6 89
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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