delphi实现注册表的操作


本文整理自网络,侵删。

 uses //加 registry; 这是第1步
var reg:tregistry; 定义变量这是第2步
Reg := TRegistry.Create 创建一个TRegistry对象这是第3步
{WriteString写入一个字符串值,WriteInteger写入一个整数值}
{ReadString读取一个字符串值,ReadInteger读取一个整数值}
{OpenKey('software',true)键值不存在的时候,则自动创建该键}
{OpenKey('software',false)只打开该键,若不存在则返回空值,并不创建该键}
例子1:实现开机自启动
procedure TForm1.Button1Click(Sender: TObject);
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',true) then
begin
WriteString('6331905',application.ExeName );
end; {WriteString写入一个字符串值,WriteInteger写入一个整数值}
CloseKey;//关闭主键
free;
end;
end;
//*************************************************************************
例子2:注册表操作
//单项操作例子 ************************************************************
procedure TForm1.Button1Click(Sender: TObject);
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\111',false) then
begin
memo1.lines.add(ReadString('6331905')); //读
end;
CloseKey;//关闭主键
free;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\111',true) then
begin
WriteString('6331905',application.ExeName ); //写
end;
CloseKey;//关闭主键
free;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\111',false) then
begin
DeleteValue('6331905'); //删除6331905项
end;
CloseKey;//关闭主键
free;
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\',false) then
begin
Deletekey('111'); //删除111目录
end;
CloseKey;//关闭主键
free;
end;
end;
//连续操作例子***********************************************************
/delphi实行一键多项写注册表
procedure TForm1.Button1Click(Sender: TObject);
begin
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\111',true) then
begin
WriteString('555',application.ExeName ); //写
WriteString('666',application.ExeName ); //写
WriteInteger('777',25 ); //写dword值
end;
CloseKey;//关闭主键
free;
end;
//*****************************************************************************
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SYSTEM\111',true) then
begin
WriteString('555',application.ExeName ); //写
WriteString('666',application.ExeName ); //写
WriteInteger('777',25 ); //写dword值
end;
CloseKey;//关闭主键
free;
end;
//******************************************************************************
reg := TRegistry.Create;
with reg do
begin
RootKey := HKEY_CURRENT_USER;
if OpenKey('SYSTEM\111',true) then
begin
WriteString('555',application.ExeName ); //写
WriteString('666',application.ExeName ); //写
WriteInteger('777',25 ); //写dword值
end;
CloseKey;//关闭主键
free;
end;
end;
end.

end;
end;
end.

相关阅读 >>

Delphi从内存流中判断图片格式

Delphi正则表达式

Delphi异常处理try except语句和try finally语句用法以及区别

Delphi 简单字符串截取函数

Delphi实现获取文件及文件夹大小(支持超过2g的大文件)

Delphi中的布尔类型

pe结构详细图

Delphi10.3构造一个json数据的第三种方法,并格式化输出

Delphi xe6 android拨号函数

Delphi 读取utf-8格式的文件内容

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...