Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to search for a substring in a registry tree Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
25-Feb-03
Category
Win API
Language
Delphi 6.x
Views
105
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Lou Adler

How do I iterate through the entries of HKLM and look for a particular string?

Answer:

Searching for a substring in a registry tree:
1   
2   procedure SearchRegistry(aRoot: HKEY; searchfor: string; resultlist: TStrings);
3   
4     procedure EnumKey(const keyname: string);
5   
6       function VName(const valuename: string): string;
7       begin
8         if Length(valuename) = 0 then
9           Result := '@'
10        else
11          Result := valuename;
12      end;
13  
14    var
15      reg: TRegistry;
16      temp: TStringList;
17      S: string;
18      i: Integer;
19    begin
20      reg := TRegistry.Create;
21      try
22        reg.Rootkey := aRoot;
23        if reg.OpenKeyReadOnly(keyname) then
24        begin
25          {Enumerate the values}
26          temp := TStringList.Create;
27          try
28            reg.GetValueNames(temp);
29            for i := 0 to temp.Count - 1 do
30            begin
31              if reg.GetDatatype(temp[i]) = rdString then
32              begin
33                S := reg.ReadString(temp[i]);
34                if Length(S) > 0 then
35                begin
36                  if Pos(searchfor, AnsiUpperCase(S)) > 0 then
37                    resultlist.add(Format('%s %s ="%s"', [keyname, Vname(temp[i]), 
38  S]));
39                end;
40              end;
41            end;
42            temp.Clear;
43            {Enumerate the subkeys}
44            if reg.HasSubKeys then
45            begin
46              reg.GetKeyNames(temp);
47              for i := 0 to temp.count - 1 do
48                EnumKey(keyname + '\' + temp[i]);
49            end;
50          finally
51            temp.free;
52          end;
53        end;
54        reg.CloseKey;
55      finally
56        reg.free;
57      end;
58    end;
59  
60  begin
61    searchfor := AnsiUpperCase(searchfor);
62    EnumKey(EmptyStr);
63  end;
64  
65  //Used like this:
66  
67  procedure TForm1.Button1Click(Sender: TObject);
68  begin
69    Memo1.clear;
70    Screen.Cursor := crHourglass;
71    try
72      SearchRegistry(HKEY_CLASSES_ROOT, 'internet', memo1.lines);
73    finally
74      Screen.Cursor := crDefault;
75    end;
76  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC