delphi让exe开机自启动

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

posted @ 2015-10-17 18:17  王云盼  阅读(517)  评论(0编辑  收藏  举报