需要单元Registry;
procedure SetAutoRun(ok: boolean);
varReg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', true);
if ok then
begin
Reg.WriteString(Application.Title, ExpandFileName(ParamStr(0)));
end
else
begin
reg.DeleteValue(Application.Title);
end;
Reg.CloseKey;
finally
Reg.Free;
end;
end;
注册表设置自启动
本文介绍了一种使用Delphi通过操作Windows注册表实现程序自启动的方法。具体步骤包括创建TRegistry实例,设置根键为HKEY_LOCAL_MACHINE,并打开指定键值路径。若需启用自启动,则写入程序标题及路径;反之则删除该键值。
1万+

被折叠的 条评论
为什么被折叠?



