// 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. |
|