注册表递归函数

 //使用方法:(遍历根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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值