开机自动运行 procedure TMainFrm.N5Click(Sender: TObject); var FilePath:string; Reg:Tregistry; SubKey:string; begin N5.Checked:=not N5.Checked; Reg:=Tregistry.Create; Reg.RootKey:=hkey_local_machine; FilePath:=Application.ExeName; SubKey:='\Software\Microsoft\Windows\CurrentVersion\run';// ???????? if N5.Checked=true then try if reg.OpenKey(SubKey,true) then if not reg.ValueExists(ExtractFileName(Application.ExeName)) then reg.WriteString(ExtractFileName(Application.ExeName),FilePath); finally reg.CloseKey; reg.Free; end else try if reg.OpenKey(SubKey,false) then if reg.ValueExists(ExtractFileName(Application.ExeName)) then reg.DeleteValue(ExtractFileName(Application.ExeName)); finally reg.CloseKey; reg.Free; end;end;
把你的程序写成一个SERVICE;不用登陆就可运行
procedure TMainFrm.FormCreate(Sender: TObject); var registerTemp : TRegistry; tmpStr : string; begin registerTemp := TRegistry.Create; with registerTemp do begin RootKey := HKEY_LOCAL_MACHINE; if OpenKey('Software\Microsoft\Windows\CurrentVersion\run',True) then begin readkey(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\run', extractfilename(Application.ExeName),tmpStr); if tmpStr<>'' then //DeleteRegistry(extractfilename(Application.ExeName)); DeleteValue(extractfilename(Application.ExeName)); WriteString(extractfilename(Application.ExeName),Application.ExeName); end; CloseKey; end; end;
//寫注冊表 procedure TForm1.FormShow(Sender: TObject); var tempreg:TRegistry; begin tempreg:=TRegistry.Create; tempreg.RootKey:=HKEY_LOCAL_MACHINE; tempreg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True); tempreg.WriteString('test',Application.Exename); tempreg.Closekey; tempreg.Free; end;
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
procedure TMainFrm.N5Click(Sender: TObject);
var
FilePath:string;
Reg:Tregistry;
SubKey:string;
begin
N5.Checked:=not N5.Checked;
Reg:=Tregistry.Create;
Reg.RootKey:=hkey_local_machine;
FilePath:=Application.ExeName;
SubKey:='\Software\Microsoft\Windows\CurrentVersion\run';// ????????
if N5.Checked=true then try
if reg.OpenKey(SubKey,true) then
if not reg.ValueExists(ExtractFileName(Application.ExeName)) then
reg.WriteString(ExtractFileName(Application.ExeName),FilePath);
finally
reg.CloseKey;
reg.Free; end
else
try
if reg.OpenKey(SubKey,false) then
if reg.ValueExists(ExtractFileName(Application.ExeName)) then
reg.DeleteValue(ExtractFileName(Application.ExeName));
finally
reg.CloseKey;
reg.Free;
end;end;
var
registerTemp : TRegistry;
tmpStr : string;
begin
registerTemp := TRegistry.Create;
with registerTemp do
begin
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('Software\Microsoft\Windows\CurrentVersion\run',True) then
begin
readkey(HKEY_LOCAL_MACHINE,
'Software\Microsoft\Windows\CurrentVersion\run',
extractfilename(Application.ExeName),tmpStr);
if tmpStr<>'' then
//DeleteRegistry(extractfilename(Application.ExeName)); DeleteValue(extractfilename(Application.ExeName)); WriteString(extractfilename(Application.ExeName),Application.ExeName);
end;
CloseKey;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
var
tempreg:TRegistry;
begin tempreg:=TRegistry.Create;
tempreg.RootKey:=HKEY_LOCAL_MACHINE;
tempreg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True);
tempreg.WriteString('test',Application.Exename);
tempreg.Closekey;
tempreg.Free;
end;
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
如果找简单的就直接放到开始启动菜单里
如果没有界面做成Service也是一种不错的选择