Q&A

  • 레지스트리 에대하여..
안녕하세요.

레지스트리 편집기에서 찾기에서 주어진문자열로 키나문자열를 찾을수 있듯이 프로그램상에서 키나문자열을 찾을수 있는 방법은 없을까요..

TRegistry의 메소드에는 그러한 함수가 없더라구요.(제가 못찾은건지..)

알려주시면 감사하겠습니다.

1  COMMENTS
  • Profile
    김영대 1999.05.14 21:06
    이호선 wrote:

    > 안녕하세요.

    > 레지스트리 편집기에서 찾기에서 주어진문자열로 키나문자열를 찾을수 있듯이 프로그램상에서 키나문자열을 찾을수 있는 방법은 없을까요..

    > TRegistry의 메소드에는 그러한 함수가 없더라구요.(제가 못찾은건지..)

    > 알려주시면 감사하겠습니다.



    // RadioGroup 의 Items 에 아래 5개의 값으로

    // HKEY_CURRENT_USER

    // HKEY_LOCAL_MACHINE

    // HKEY_CLASSES_ROOT

    // HKEY_CURRENT_CONFIG

    // HKEY_USERS

    // 항목을 추가하세요



    unit Unit1;



    interface



    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    Registry, StdCtrls, ExtCtrls;



    type

    TForm1 = class(TForm)

    ListBox1: TListBox;

    Button1: TButton;

    Label1: TLabel;

    RadioGroup1: TRadioGroup;

    procedure Button1Click(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure RadioGroup1Click(Sender: TObject);

    private

    { Private declarations }

    FRootKey: HKEY;

    procedure GetSubKeys(ARegistry: TRegistry; AKey: string;

    ALevel: integer; AStrings: TStrings);

    public

    { Public declarations }

    end;



    var

    Form1: TForm1;



    implementation

    {$R *.DFM}



    const

    CBaseKey = '';



    procedure TForm1.GetSubKeys(ARegistry: TRegistry; AKey: string;

    ALevel: integer; AStrings: TStrings);

    var

    fill: string;

    i: integer;

    j: integer;

    thisKey: string;

    tmpKeys: TStringList;

    begin

    if ARegistry.OpenKey(AKey, false) then

    begin

    Label1.Caption := AKey;

    Application.ProcessMessages;

    try

    ARegistry.GetKeyNames(AStrings);



    if AStrings.Count > 0 then

    begin

    for i := AStrings.Count - 1 downto 0 do

    begin

    tmpKeys := TStringList.Create;

    try

    thisKey := AKey + '' + AStrings[i];

    Label1.Caption := thisKey;

    Application.ProcessMessages;

    GetSubKeys(ARegistry, thisKey, ALevel, tmpKeys);

    Inc(ALevel);

    try

    SetLength(fill, ALevel * 2);

    FillChar(fill[1], Length(fill), ' ');



    for j := tmpKeys.Count - 1 downto 0 do

    AStrings.Insert(i + 1, fill + tmpKeys[j]);

    finally

    Dec(ALevel);

    end;

    finally

    tmpKeys.Free;

    end;

    end;

    end;

    finally

    ARegistry.CloseKey;

    end;

    end;

    end;



    procedure TForm1.Button1Click(Sender: TObject);

    const

    level: integer = 0;

    var

    fill: string;

    i: integer;

    j: integer;

    theKeys: TStringList;

    theRegistry: TRegistry;

    tmpKeys: TStringList;

    begin

    ListBox1.Clear;



    theRegistry := TRegistry.Create;

    try

    with theRegistry do

    begin

    RootKey := FRootKey;

    OpenKey(CBaseKey, False);

    theKeys := TStringList.Create;

    try

    GetKeyNames(theKeys);



    if theKeys.Count > 0 then

    begin

    for i := theKeys.Count - 1 downto 0 do

    begin

    tmpKeys := TStringList.Create;

    try

    GetSubKeys(theRegistry, CBaseKey + theKeys[i], level, tmpKeys);

    Inc(level);

    try

    SetLength(fill, level * 2);

    FillChar(fill[1], Length(fill), ' ');



    for j := tmpKeys.Count - 1 downto 0 do

    theKeys.Insert(i + 1, fill + tmpKeys[j]);

    finally

    Dec(level);

    end;

    finally

    tmpKeys.Free;

    end;

    end;

    end;



    ListBox1.Items.Assign(theKeys);

    ListBox1.Items.SaveToFile('C:Temp'

    + RadioGroup1.Items[RadioGroup1.ItemIndex]

    + '.Txt');

    Label1.Caption := IntToStr(ListBox1.Items.Count);

    finally

    theKeys.Free;

    end;

    end;

    finally

    theRegistry.Free;

    end;

    end;



    procedure TForm1.FormCreate(Sender: TObject);

    begin

    RadioGroup1.ItemIndex := 0;

    end;



    procedure TForm1.RadioGroup1Click(Sender: TObject);

    begin

    case RadioGroup1.ItemIndex of

    0: FRootKey := HKEY_CURRENT_USER;

    1: FRootKey := HKEY_LOCAL_MACHINE;

    2: FRootKey := HKEY_CLASSES_ROOT;

    3: FRootKey := HKEY_CURRENT_CONFIG;

    4: FRootKey := HKEY_USERS;

    end;

    end;



    end.