使用 TRegistry 类[1]: 显示各主键下的项

使用 TRegistry 类[1]: 显示各主键下的项

{XP 注册表中的主键}
HKEY_CLASSES_ROOT    {文件类型信息} 
HKEY_CURRENT_USER    {当前用户信息}
HKEY_LOCAL_MACHINE   {软硬件信息} 
HKEY_USERS           {所有用户信息} 
HKEY_CURRENT_CONFIG  {当前配置信息}

{Delphi 定义的常量}
HKEY_CLASSES_ROOT     = DWORD($80000000);
HKEY_CURRENT_USER     = DWORD($80000001);
HKEY_LOCAL_MACHINE    = DWORD($80000002);
HKEY_USERS            = DWORD($80000003);
HKEY_PERFORMANCE_DATA = DWORD($80000004);
HKEY_CURRENT_CONFIG   = DWORD($80000005);
HKEY_DYN_DATA         = DWORD($80000006);
本例效果图:

使用 TRegistry 类[1]: 显示各主键下的项

代码文件:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    RadioGroup1: TRadioGroup;
    procedure FormCreate(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Registry;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox1.Align := alLeft;
  RadioGroup1.Items.CommaText := 'HKEY-CLASSES-ROOT,' +
                                 'HKEY-CURRENT-USER,' +
                                 'HKEY-LOCAL-MACHINE,' +
                                 'HKEY-USERS,' +
                                 'HKEY-CURRENT-CONFIG';
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
var
  reg: TRegistry;
begin
  reg := TRegistry.Create;

  case RadioGroup1.ItemIndex of
    0: reg.RootKey := HKEY_CLASSES_ROOT;
    1: reg.RootKey := HKEY_CURRENT_USER; {这是 RootKey 的默认值}
    2: reg.RootKey := HKEY_LOCAL_MACHINE;
    3: reg.RootKey := HKEY_USERS;
    4: reg.RootKey := HKEY_CURRENT_CONFIG;
  end;

  reg.OpenKey('', False);
  reg.GetKeyNames(ListBox1.Items);
  reg.CloseKey;
  reg.Free;
end;

end.
窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 176
  ClientWidth = 325
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object ListBox1: TListBox
    Left = 0
    Top = 8
    Width = 153
    Height = 134
    ItemHeight = 13
    TabOrder = 0
  end
  object RadioGroup1: TRadioGroup
    Left = 159
    Top = 8
    Width = 158
    Height = 160
    Caption = 'RadioGroup1'
    TabOrder = 1
    OnClick = RadioGroup1Click
  end
end
posted on 2008-08-23 21:51  万一  阅读(5306)  评论(10)  编辑  收藏
上一篇:windows平台下 c++获取 系统版本 网卡 内存 CPU 硬盘 显卡信息


下一篇:32/64 MinHook 库的使用方式