当前位置:首页 > Windows程序 > 正文

delphi让exe开机自启动

2021-03-24 Windows程序

procedure AutoRunOnSystemStart(Title, FileName: String);
const
  _Software_Microsoft_Windows_CurrentVersion_Run_ : string = ‘\Software\Microsoft\Windows\CurrentVersion\Run\‘;
var
  Reg: TRegistry;
  Key: String;
begin
  Reg := TRegistry.Create;                // 创建一个新的注册表
  Reg.RootKey := HKEY_LOCAL_MACHINE;      // 将根键设置为HKEY_LOCAL_MACHINE
  Key := _Software_Microsoft_Windows_CurrentVersion_Run_; // 键Run
  Reg.OpenKey(Key, True);                 // 打开这个键
  Reg.WriteString(Title, FileName);       // 在Reg这个键中写入数据名称和数据值
  Reg.CloseKey;
  Reg.Free;
end;

AutoRunOnSystemStart(self.Name, paramstr(0));           // 开机自启动

paramstr(0);为当前目录下exe名,,delphi7下可用Application.ExeName

delphi让exe开机自启动

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/66531.html