注册表问题

zhshj1963 2003-05-19 09:43:25
注册表操作中 ,GetKeyNames是用来获取子键名称的,用于返回当前主键下各子键的名称,我的问题是它怎么用,能不能写个例子???
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bingbing2008 2003-05-19
  • 打赏
  • 举报
回复
{Unit1的代码:}

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs,Registry, StdCtrls, Buttons, CheckLst; //Registry为后加上的

type
 TForm1 = class(TForm)
 CheckListBox1: TCheckListBox;
 SFSC: TBitBtn;
 Sc: TBitBtn;
 Bf: TBitBtn;
 Dr: TBitBtn;
 procedure SFSCClick(Sender: TObject);//是否删除
 procedure ScClick(Sender: TObject);//删除
 procedure BfClick(Sender: TObject);//注册表备份
 procedure DrClick(Sender: TObject);//导入备份
 procedure FormCreate(Sender: TObject);
 private
  { Private declarations }
 public
  procedure Createparams(Var Params:TCreateParams);override;
  { Public declarations }
end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Createparams(var Params:TCreateParams);
{保证本程序总在窗口最上层,可供你别的程序借鉴两个相同功能的程序碰到一块,谁先运行,谁在下面}
var
 wndParnet:HWND;
begin
 Inherited CreateParams(Params);
 With Params do
 begin
  EXStyle:=ExStyle or WS_EX_TOPMOST OR WS_EX_ACCEPTFILES;
  wndParnet:=GetDesktopWindow;
 end;
end;

procedure TForm1.SFSCClick(Sender: TObject); // 看看是否删除
var
 intIndex:integer;
 registryTemp:TRegistry;
 stringTemp:TStrings;
 RunFile:string;
begin
 checkListBox1.Clear;
 registryTemp:=TRegistry.Create;
 stringTemp:=TStringList.Create;
 with registryTemp do
 begin
  RootKey:=HKEY_LOCAL_MACHINE;
  if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',false) then
   GetKeyNames(stringTemp);
 CloseKey;
 end;
 for intIndex:= 0 to stringTemp.Count-1 do
  CheckListBox1.Items.Add(stringTemp.Strings[intIndex]);
 registryTemp.free;
 stringTemp.Free ;
 RunFile:='Rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,0';
 WinExec(pchar(RunFile),SW_HIDE);
 {打开“控制面板”的“添加/删除选项”,程序运行到这儿,你就明白,我为什么要让我的程序总在视窗的最上层,不然被别人盖了,多不好玩!}
 Form1.Caption:='如果删除不对,请击“导入备份”按钮';
end;

procedure TForm1.ScClick(Sender: TObject); //删除
var
 i:integer;
 registryTemp:TRegistry;
 strTemp:String;
begin
 for i := 0 to (CheckListBox1.Items.Count-1) do
  if CheckListBox1.Checked[i] then
  begin
   strTemp:=CheckListBox1.Items.Strings[i];
   registryTemp:=TRegistry.Create;
   registryTemp.RootKey :=HKEY_LOCAL_MACHINE;
   registryTemp.OpenKey('
SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',true);
   registryTemp.DeleteKey(strTemp);
   registryTemp.Free;
  end;
 Form1.Caption:='请击“是否删除”按钮,检查删除情况';
end;

procedure TForm1.BfClick(Sender: TObject); //注册表备份
var
 RunFile:string;
begin
 DeleteFile('Backup.reg');
 RunFile:='Regedit /E Backup.reg HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall';
 WinExec(pchar(RunFile),SW_HIDE);
 Form1.Caption:='请选择要清除的项,然后击“删除”按钮';
end;

procedure TForm1.DrClick(Sender: TObject); //导入备份
var
 Runfile:string;
 intIndex:integer;
 registryTemp:TRegistry;
 stringTemp:TStrings;
begin
 RunFile:='Regedit /s Backup.reg ';
 WinExec(pchar(RunFile),SW_HIDE);
 checkListBox1.Clear;
 registryTemp:=TRegistry.Create;
 stringTemp:=TStringList.Create;
 with registryTemp do
 begin
  RootKey:=HKEY_LOCAL_MACHINE;
  if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',false) then
   GetKeyNames(stringTemp);
  CloseKey;
 end;
 for intIndex:= 0 to stringTemp.Count-1 do
  CheckListBox1.Items.Add(stringTemp.Strings[intIndex]);
 registryTemp.free;
 stringTemp.Free ;
 Form1.Caption:='已导入备份,请重新选择删除';
end;

procedure TForm1.FormCreate(Sender: TObject);
var
 intIndex:integer;
 registryTemp:TRegistry;
 stringTemp:TStrings;
begin
 checkListBox1.Clear;
 registryTemp:=TRegistry.Create;
 stringTemp:=TStringList.Create;
 with registryTemp do
 begin
  RootKey:=HKEY_LOCAL_MACHINE;
  if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',false) then
   GetKeyNames(stringTemp);
  CloseKey;
 end;
 for intIndex:= 0 to stringTemp.Count-1 do
  CheckListBox1.Items.Add(stringTemp.Strings[intIndex]);
 registryTemp.free;
 stringTemp.Free ;
 Form1.Caption:='“删除”之前,请先备份';
end;

End.

你看看吧!
firetoucher 2003-05-19
  • 打赏
  • 举报
回复
ft,在TRegKey的帮助里面有完整的例程!

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧