//使用方法:(遍历根hkey_classes_root)
// fxxx(HKEY_CLASSES_ROOT,'','');
Procedure TForm1.fxxx(root:hkey;Fatherkey,KeyName: String);
Var
tstring: tstrings;
i: integer;
registry: TRegistry;
Begin
// 定位主键的位置
registry := TRegistry.create;
registry.RootKey := ROOT;
if fatherkey<>'' then
fatherkey:=fatherkey+'/'+keyname
else fatherkey:=keyname;
registry.OpenKey(fatherkey, false);
tstring := TStringList.create;
If registry.HasSubKeys Then
Begin
// ListBox1.Items.Clear;
registry.GetKeyNames(tstring);
// tstring := ListBox1.Items;
If tstring.Count < 1 Then
exit;
For i := 0 To tstring.Count - 1 Do
Begin
Memo1.Lines.Add('.../'+fatherkey+'/'+tstring.Strings[i]);
fxxx(root,fatherkey,tstring.Strings[i]);
End;
End;
tstring.Destroy;
End;
//===========================封装成为线程执行==============================
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, registry;
type
findregistry = class(TThread)
private
{ Private declarations }
Procedure fxxx(root:hkey;Fatherkey,KeyName: String);
protected
procedure Execute; override;
end;
implementation
uses unit1;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure findregistry.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ findregistry }
Procedure findregistry.fxxx(root:hkey;Fatherkey,KeyName: String);
Var
tstring: tstrings;
i: integer;
registry: TRegistry;
Begin
// 定位主键的位置
registry := TRegistry.create;
registry.RootKey := ROOT;
if fatherkey<>'' then
fatherkey:=fatherkey+'/'+keyname
else fatherkey:=keyname;
registry.OpenKey(fatherkey, false);
tstring := TStringList.create;
If registry.HasSubKeys Then
Begin
// ListBox1.Items.Clear;
registry.GetKeyNames(tstring);
// tstring := ListBox1.Items;
If tstring.Count < 1 Then
exit;
For i := 0 To tstring.Count - 1 Do
Begin
form1.Memo1.Lines.Add('.../'+fatherkey+'/'+tstring.Strings[i]);
fxxx(root,fatherkey,tstring.Strings[i]);
End;
End;
tstring.Destroy;
End;
procedure findregistry.Execute;
begin
fxxx(HKEY_CLASSES_ROOT,'','');
end;
end.