RunOnStartup(self.SoeAppInfo1.AppName, ParamStr(0), chkAutoStart.Checked);
procedure TServerForm.RunOnStartup(sProgTitle, sCmdLine: string;
bStartup: boolean);
var
sKey: string;
reg : TRegIniFile;
begin
sKey := ''; //sKey := 'Once' if you wish it to only run on the next time you startup.
if bStartup = false then//If value passed is false, then value deleted from Registry.
begin
try
reg := TRegIniFile.Create('');
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.DeleteKey(
'Software\Microsoft'
+ '\Windows\CurrentVersion\Run'
+ sKey + #0,
sProgTitle);
reg.Free;
exit;
except//Using Try Except so that if value can not be placed in registry, it
//will not give and error.
end;
end;
try
reg := TRegIniFile.Create('');
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.WriteString(
'Software\Microsoft'
+ '\Windows\CurrentVersion\Run'
+ sKey + #0,
sProgTitle,
sCmdLine);
reg.Free;
except
end;
end;