其他分享
首页 > 其他分享> > Delphi 开机自动启动函数SetAutoRun

Delphi 开机自动启动函数SetAutoRun

作者:互联网

转载自:https://blog.csdn.net/listest/article/details/121272294

procedure SetAutoRun(isRun: Boolean);
var
  oAutoRunRegister: TRegistry;
begin
  oAutoRunRegister := TRegistry.Create;
  try
    oAutoRunRegister.RootKey := HKEY_CURRENT_USER;
    oAutoRunRegister.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', False);
    if isRun then
    begin
      if not oAutoRunRegister.ValueExists('appEXEName') then
      begin
        oAutoRunRegister.WriteString('appEXEName', Application.ExeName);
      end;
    end
    else
    begin
      if oAutoRunRegister.ValueExists('appEXEName') then
      begin
        oAutoRunRegister.DeleteValue('appEXEName');
      end;
    end;
  finally
    oAutoRunRegister.Free;
  end;
end;

标签:TRegistry,begin,end,ValueExists,Delphi,开机,SetAutoRun,appEXEName,oAutoRunRegister
来源: https://www.cnblogs.com/YXGust/p/16576853.html