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中强制idhttp使用http1.1

Delphi webbrowser控件属性

Delphi xe 中使用正则表达式

Delphi 数据库获取所有用户名

Delphi 2009 之 tstringbuilder 类[7]: tostring

Delphi net.httpclient用最精简的代码获取网页数据

Delphi 获取指定进程中的~内存数据

Delphi中始终用webbrowser打开网页

Delphi 单击最小化按钮隐藏单击托盘显示

Delphi中webbrowser自动登录路由器网页

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



打赏

取消

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

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

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

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

评论

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