分享
 
 
 

Delphi快速读出注册表

王朝delphi·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

file://不用再修改VCL.

file://结构定义的可能不是很好。

/////main.dfm

object Form1: TForm1

Left = 192

Top = 107

Width = 544

Height = 375

Caption = '注册表'

Color = clBtnFace

Font.Charset = GB2312_CHARSET

Font.Color = clWindowText

Font.Height = -12

Font.Name = '宋体'

Font.Style = []

OldCreateOrder = False

OnCreate = FormCreate

PixelsPerInch = 96

TextHeight = 12

object Splitter1: TSplitter

Left = 209

Top = 0

Width = 3

Height = 348

Cursor = crHSplit

end

object TreeView1: TTreeView

Left = 0

Top = 0

Width = 209

Height = 348

Align = alLeft

Indent = 19

TabOrder = 0

OnChange = TreeView1Change

OnExpanding = TreeView1Expanding

end

object ListView1: TListView

Left = 212

Top = 0

Width = 324

Height = 348

Align = alClient

Columns = <

item

AutoSize = True

Caption = '名称'

end

item

AutoSize = True

Caption = '数据'

end>

TabOrder = 1

ViewStyle = vsReport

end

end

////////////////////////////////////////////////////////

file://main.pas

unit main;

interface

uses

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

Registry, ComCtrls, ExtCtrls;

type

TForm1 = class(TForm)

Splitter1: TSplitter;

TreeView1: TTreeView;

ListView1: TListView;

procedure FormCreate(Sender: TObject);

procedure TreeView1Expanding(Sender: TObject; Node: TTreeNode;

var AllowExpansion: Boolean);

procedure TreeView1Change(Sender: TObject; Node: TTreeNode);

private

procedure ExpandSubNode(Node:TTreeNode;Info:HKEY;Index:Integer;bRoot:Boolean=False);

procedure GetKeyValue(Node: TTreeNode; var SubKey: String);

{ Private declarations }

public

{ Public declarations }

end;

type TNodeMyInfo=record

bRootNode:Boolean;

bVisitored:Boolean;

Info:HKey;

Index:Integer;

end;

type PNodeInfo=^TNodeMyInfo;

var

Form1: TForm1;

implementation

{$R *.DFM}

const

MaxNumber=5;

RootValue:array [0..MaxNumber] of DWord=

(

HKEY_CLASSES_ROOT,

HKEY_CURRENT_USER,

HKEY_LOCAL_MACHINE,

HKEY_USERS,

HKEY_CURRENT_CONFIG,

HKEY_DYN_DATA

);

RootKeyName :array [0..MaxNumber] of String=

(

'HKEY_CLASSES_ROOT',

'HKEY_CURRENT_USER',

'HKEY_LOCAL_MACHINE',

'HKEY_USERS',

'HKEY_CURRENT_CONFIG',

'HKEY_DYN_DATA'

);

procedure TForm1.FormCreate(Sender: TObject);

const MyComputer='我的电脑';

var

i:Integer;

RootNode,SubNode:TTreeNode;

begin

RootNode:=TreeView1.Items.Add(nil,MyComputer);

RootNode.ImageIndex :=1;

for i:=0 to MaxNumber do

begin

SubNode:=TreeView1.Items.AddChild(RootNode,RootKeyName[i]);

SubNode.ImageIndex:=1;

ExpandSubNode(SubNode,RootValue[i],I,True);

end;

end;

procedure TForm1.ExpandSubNode(Node:TTreeNode;Info:HKEY;Index:Integer;bRoot:Boolean=False);

var

List:TStringList;

SubKey:string;

Reg:TRegistry;

i:Integer;

P:PNodeInfo;

tempNode:TTreeNode;

begin

New(P);

P.bRootNode :=bRoot;

P.Info :=Info;

P.Index :=Index;

P.bVisitored :=False;

Node.Data:=P;

Reg:=TRegistry.Create;

file://case

Reg.RootKey :=Info;

List:=TStringList.Create;

GetKeyValue(Node,SubKey);

if Reg.OpenKey(SubKey,False) then

begin

Reg.GetKeyNames(List);

List.Sort;

for i:=0 to List.Count-1 do

begin

tempNode:=TreeView1.Items.AddChild(Node,List.Strings[i]);

tempNode.ImageIndex :=1;

end;

end;

Reg.CloseKey;

Reg.Free;

List.Free;

end;

procedure TForm1.GetKeyValue(Node:TTreeNode;var SubKey:String);

var ParentNode:TTreeNode;

begin

if (Node.Level =0) or (Node.Level=1) then Exit;

SubKey:='\'+Node.Text;

ParentNode:=Node.Parent;

while (ParentNode<>nil) and (ParentNode.Level<>1) do

begin

SubKey:='\'+ParentNode.Text +SubKey;

ParentNode:=ParentNode.Parent;

end;

SubKey:=SubKey+'\';

end;

procedure TForm1.TreeView1Expanding(Sender: TObject; Node: TTreeNode;

var AllowExpansion: Boolean);

var I:integer;

begin

if Node.Level=0 then Exit;

if not TNodeMyInfo(Node.Data^).bVisitored then

begin

Screen.Cursor:=crHourGlass;

for i:=0 to Node.Count-1 do

(Node.Item[i],TNodeMyInfo(Node.Data^).Info,TNodeMyInfo(Node.data^).Index);

PNodeInfo(Node.Data).bVisitored:=True;

Screen.Cursor:=crDefault;

end;

end;

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);

var

Reg:TRegistry;

SubString:String;

List:TStringList;

I:integer;

Item:TListItem;

DataInfo:TRegDataInfo;

Value:Variant;

P:String;

begin

if Node.Level=0 then Exit;

ListView1.Items.Clear;

List:=TStringList.Create;

Reg:=TRegistry.Create;

Reg.RootKey:=TNodeMyInfo(Node.Data^).Info;

GetKeyValue(Node,SubString);

if Reg.OpenKey(SubString,False) then

begin

Reg.GetValueNames(List);

List.Sort;

for i:=0 to List.Count-1 do

begin

Value:='未设键值'; reg.read

Reg.GetDataInfo(List.Strings[i],DataInfo);

case DataInfo.RegData of

rdUnknown:

Value:='Unknown';

rdExpandString:

Value:=Reg.ReadString(List.Strings[i]);

rdBinary:

begin

Value:=Reg.ReadBinaryData(List.Strings[i],P,DataInfo.DataSize);

Value:=P;

end;

rdString:

Value:=Reg.ReadString(List.Strings[i]);

rdInteger:

Value:=Reg.ReadInteger(List.Strings[i]);

end;

Value:=varToStr(Value);

Item:=ListView1.Items.Add;

if List.Strings[i]='' then

Item.Caption:='(默认)'

else

Item.Caption :=List.Strings[i];

Item.SubItems.Add(Value);

end;

end;

Reg.CloseKey;

Reg.Free;

List.Free;

end;

end.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有