这是我写的可以控制是否随机启动的
procedure Tform1.autorun(key:boolean);
var
ini:Tinifile;
begin
ini:=Tinifile.Create(ExtractFilePath(Application.ExeName)+'conifg.ini');
try
ini.WriteBool('CONFIG','AUTORUN',key);
finally
ini.Free;
end;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
autorun(checkbox1.Checked);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
ini:Tinifile;
reg:TRegistry;
begin
reg:=Tregistry.Create;
ini:=Tinifile.Create(ExtractFilePath(Application.ExeName)+'conifg.ini');
try
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',True) then
begin
if ini.ReadBool('CONFIG','AUTORUN',true) then
reg.WriteString(ExtractFileName(Application.ExeName),'"'+Application.ExeName+'"')
else
reg.DeleteValue(ExtractFileName(Application.ExeName));
reg.CloseKey;
end;
finally
ini.Free;
reg.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
checkbox1.Checked:=true;
end;