Use wildcards in registry?

Hi,
For example, in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft, there are many subfolders, such as "Plus!", "Windows" which each of these subfolders contains a lot of string, binary, dword entries.
What I want to know is how can I get all the names of those subfolders?
(ie. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\*)
How to get the * ?
Secondly, how to get all the names of those string, binary, dword type entries?

Thanks
yingkitAsked:
Who is Participating?
 
intheCommented:
Hi Meikl,
here the way i wrote about:
or a handy backup utility ;-)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,Registry;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Procedure ExportRegistryBranch (rootsection : Integer; regroot:String;
filename:String);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


Function dblBackSlash(t:string):string;
var k:longint;
begin
  result:=t;                                       {Strings are not allowed
to have}
  for k:=length(t) downto 1 do                     {single backslashes}
     if result[k]='\' then insert('\',result,k);
end;


Procedure tfORM1.ExportRegistryBranch (rootsection : Integer;  regroot:String;
filename:String);
var reg:tregistry;
    f:textfile;
    p:PCHAR;

    Procedure ProcessBranch(root:string);                   {recursive
sub-procedure}
    var values,keys:tstringlist; i,j,k:longint;
        s,t:string;                            {longstrings are on the heap,
not on the stack!}
    begin
         Writeln(f);                           {write blank line}
         case rootsection of
           HKEY_CLASSES_ROOT    :s:='HKEY_CLASSES_ROOT';
           HKEY_CURRENT_USER    :s:='HKEY_CURRENT_USER';
           HKEY_LOCAL_MACHINE   :s:='HKEY_LOCAL_MACHINE';
           HKEY_USERS           :s:='HKEY_USERS';
           HKEY_PERFORMANCE_DATA:s:='HKEY_PERFORMANCE_DATA';
           HKEY_CURRENT_CONFIG  :s:='HKEY_CURRENT_CONFIG';
           HKEY_DYN_DATA        :s:='HKEY_DYN_DATA';
         end;
         Writeln(f,'['+s+'\'+root+']');       {write section name in
brackets}

       reg.OpenKey(root,false);
       values:=tstringlist.create;
       keys:=tstringlist.create;
       reg.getvaluenames (values);            {get all value names}
       reg.getkeynames   (keys);              {get all sub-branches}

       for i:=0 to values.count-1 do          {write all the values first}
       begin
            s:=values[i];
            t:=s;                             {s=value name}
            if s=''
                  then s:='@'                 {empty means "default value",
write as @}
                  else s:='"' + s + '"';      {else put in quotes}
            write(f,dblbackslash(s)+'=');     {write the name of the key to
the file}

            Case reg.Getdatatype(t) of        {What type of data is it?}

              rdString,rdExpandString:        {String-type}
                  Writeln(f,'"'      + dblbackslash(reg.readstring(t)+'"'));

              rdInteger      :                {32-bit unsigned long integer}
                  Writeln(f,'dword:' + inttohex(reg.readinteger(t),8));

              {write an array of hex bytes if data is "binary." Perform a
line feed
               after approx. 25 numbers so the line length stays within
limits}

              rdBinary       :
              begin
                write(f,'hex:');
                j:=reg.getdatasize(t);      {determine size}
                getmem(p,j);                {Allocate memory}
                reg.ReadBinaryData(t,p^,J); {read in the data, treat as
pchar}
                for k:=0 to j-1 do
                begin
                  Write(f,inttohex(byte(p[k]),2)); {Write byte as hex}
                  if k<>j-1 then                   {not yet last byte?}
                  begin
                    write(f,',');                  {then write Comma}
                    if (k>0) and ((k mod 25)=0)    {line too long?}
                       then writeln(f,'\');        {then write Backslash +
lf}
                  end; {if}
                end;   {for}
                freemem(p,j);                      {free the memory}
                writeln(f);                        {Linefeed}
              end;
              ELSE writeln(f,'""'); {write an empty string if datatype
illegal/unknown}
            end;{case}
       end; {for}

       reg.closekey;

       {value names all done, no longer needed}
       values.free;

       {Now al values are written, we process all subkeys}
       {Perform this process RECURSIVELY...}
       for i:=0 to keys.count-1 do
          ProcessBranch(root+'\'+keys[i]);

       keys.free; {this branch is ready}
    end;

begin
  if regroot[length(regroot)]='\' then        {No trailing backslash}
     setlength(regroot,length(regroot)-1);
  Assignfile(f,filename);                     {create a text file}
  rewrite(f);
  IF ioresult<>0 then EXIT;
  Writeln(f,'REGEDIT4');                      {"magic key" for regedit}

  reg:=tregistry.create;
  try
     reg.rootkey:=rootsection;
     ProcessBranch(regroot);                  {Call the function that writes
the branch and all subbranches}
   finally
    reg.free;                                 {ready}
    end;
    CLOSEFILE(F);
    end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ExportRegistryBranch(hkey_local_machine,'SOFTWARE\Borland\Delphi','c:\delphireg.reg')


end;

procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.lines.loadfromfile('c:\delphireg.reg');
end;
0
 
yingkitAuthor Commented:
Edited text of question.
0
 
MadshiCommented:
Look at RegEnumKey(Ex) and RegEnumValue. Pure win32 API...   :-(

Regards, Madshi.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rarigoCommented:
Hi yingkit,

   Madshi's already told you the right direction. You'll have to get used to procedures like RegDeleteValue,
RegEnumKey, RegEnumKeyEx, RegEnumValue,
RegOpenKey, RegOpenKeyEx, RegQueryInfoKey, RegQueryValue
RegQueryValueEx, RegReplaceKey.
   There's not an easy way.  :-(
   We could show you how to do this as long as we know how you intend to use them.


Tchau,
Reginaldo


0
 
intheCommented:
hi,
i dont think this is what you need but i presume you know what a .reg file looks like.
if not open one in notepad and if you want your search results to look like that i can post code for it where you would do this :

getreg(hkey_local_machine,'SOFTWARE\Microsoft','f:\microsoft.reg')

this gets all data (same as export reg)
then you can load the file into a memo or whatever..
0
 
kretzschmarCommented:
nice idea barry,

hi yingkit,


in the meanwhile
try this sample

unit reg_entries_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  MyReg : TRegistry;
  MyDataInfo : TRegDataInfo;

procedure CollectRegistry(Path :  String; Reg : TRegistry; List : TStrings);
var
  SL : TStringList;
  i : Integer;
begin
  List.Add('>-Retrieving Path : '+Path);
  SL := TStringList.Create;   // A stringlist
  try
    Reg.GetValueNames(SL);  // collect valuenames
    for i := 0 to SL.Count - 1 do
    begin
      Reg.GetDataInfo(SL.Strings[I],MyDataInfo);  // get more info
      Case MyDataInfo.RegData of                  //Get Datatypes and values
        rdString,
        rdexpandString : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           List.Add(Path+SL.Strings[I]+' : String = '+Reg.ReadString(SL.Strings[I]))
                         else List.Add(Path+SL.Strings[I]+' : String = Not Set');
        rdUnknown      : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           List.Add(Path+SL.Strings[I]+' : Unknown = Not Retrieved yet')
                         else List.Add(Path+SL.Strings[I]+' : Unknown = Not Set');
        rdInteger      : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           List.Add(Path+SL.Strings[I]+' : Integer = '+IntToStr(Reg.ReadInteger(SL.Strings[I])))
                         else List.Add(Path+SL.Strings[I]+' : Integer = Not Set');
        rdBinary       : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           List.Add(Path+SL.Strings[I]+' : Binary = Not Retrieved yet')
                         else List.Add(Path+SL.Strings[I]+' : Binary = Not Set');
        else   //type not in case
          if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
            List.Add(Path+SL.Strings[I]+' : Not Registered Typ = Not Retrieved yet')
          else List.Add(Path+SL.Strings[I]+' : Not Registered Typ = Not Set');
      end;
    end;
    Reg.GetKeyNames(SL);
    // Start recursion
    for i := 0 to SL.Count - 1 do
    begin
      if Reg.OpenKey('\' + path + SL.Strings[I],False) then  //key open
        CollectRegistry(Reg.CurrentPath +'\', Reg, List);
      Reg.OpenKey(Path,False);  //reopen current
    end;
  finally
    sl.free;  // free
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  SL : TStringList;
begin
  MyReg := TRegistry.Create;
  SL := TStringList.Create;   // A stringlist
  try
    MyReg.RootKey := HKEY_LOCAL_MACHINE;          //set rootkey
    MyReg.OpenKey('\SOFTWARE\Microsoft\',False);  // open root
    CollectRegistry(MyReg.CurrentPath,MyReg,SL);  //start Search
    Memo1.Lines.Assign(SL);  //visualize in a memo
  finally
    MyReg.Free;
    SL.Free;
  end;
end;

end.

meikl
0
 
yingkitAuthor Commented:
Actually, I want to copy all the paths to a treeview, that's why I asked this question.
0
 
kretzschmarCommented:
hi yingkit,

have modified my source, to provide a treeview instead a memo

unit reg_entries_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Registry, ImgList, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    TreeView1: TTreeView;
    ImageList1: TImageList;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  MyReg : TRegistry;
  MyDataInfo : TRegDataInfo;

procedure CollectRegistry(Path :  String;
                          Reg : TRegistry;
                          ANode : TTreeNode;
                          Nodes : TTreeNodes);
var
  TmpNode : TTreeNode;
  SL : TStringList;
  i : Integer;
  S : String;
begin
  SL := TStringList.Create;   // A stringlist
  try
    Reg.GetValueNames(SL);  // collect valuenames
    for i := 0 to SL.Count - 1 do
    begin
      Reg.GetDataInfo(SL.Strings[I],MyDataInfo);  // get more info
      Case MyDataInfo.RegData of                  //Get Datatypes and values
        rdString,
        rdexpandString : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : String = '+Reg.ReadString(SL.Strings[I])
                         else S := Path+SL.Strings[I]+' : String = Not Set';
        rdUnknown      : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : Unknown = Not Retrieved yet'
                         else S := Path+SL.Strings[I]+' : Unknown = Not Set';
        rdInteger      : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : Integer = '+IntToStr(Reg.ReadInteger(SL.Strings[I]))
                         else S := Path+SL.Strings[I]+' : Integer = Not Set';
        rdBinary       : if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
                           S := Path+SL.Strings[I]+' : Binary = Not Retrieved yet'
                         else S := Path+SL.Strings[I]+' : Binary = Not Set';
        else   //type not in case
          if Reg.ValueExists(SL.Strings[I]) then   //there is a value entry
            S := Path+SL.Strings[I]+' : Not Registered Typ = Not Retrieved yet'
          else S := Path+SL.Strings[I]+' : Not Registered Typ = Not Set';
      end;
      TmpNode := Nodes.AddChild(ANode,S);
      TmpNode.ImageIndex := 1;  //show key image
      application.ProcessMessages;  //show the tree grow
    end;
    Reg.GetKeyNames(SL);
    // Start recursion
    for i := 0 to SL.Count - 1 do
    begin
      if Reg.OpenKeyReadOnly('\' + path + SL.Strings[I]) then  //key open for read
      begin
        TmpNode := Nodes.AddChild(ANode,Reg.CurrentPath);
        TmpNode.ImageIndex := 0;  //show folder-image
        CollectRegistry(Reg.CurrentPath +'\', Reg, TmpNode, Nodes);
      end;
    end;
  finally
    sl.free;  // free
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ANode : TTreeNode;
begin
  Button1.Enabled := False;
  MyReg := TRegistry.Create;
  try
    MyReg.RootKey := HKEY_LOCAL_MACHINE;          //set rootkey
    MyReg.OpenKeyReadOnly('\SOFTWARE\Microsoft\');  // open root for read
    TreeView1.Items.Clear;                          // clear tree
    ANode := Treeview1.Items.Add(Nil,MyReg.CurrentPath);
    ANode.ImageIndex := 0;
    CollectRegistry(MyReg.CurrentPath,MyReg,ANode,TreeView1.Items);  //start Search
  finally
    MyReg.Free;
  end;
  Button1.Enabled := True;
end;

end.

meikl
0
 
yingkitAuthor Commented:
Great!  It does even more that what I want.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.