Some programs need to be set to start at boot, so I wrote a function to facilitate future use for your reference.
Copy the code code as follows:
procedure TMainForm.SetAutoRun(ok: boolean);
var
Reg:TRegistry; //First define a variable Reg of TRegistry type
begin
Reg:=TRegistry.Create;
try //Create a new key
Reg.RootKey:=HKEY_LOCAL_MACHINE; //Set the root key to HKEY_LOCAL_MACHINE
Reg.OpenKey('Software/Microsoft/Windows/CurrentVersion/Run',true);//Open a key
if ok then begin
Reg.WriteString('SMS Service',ExpandFileName(ParamStr(0))); //Write the data name and data value in the Reg key
ShowMessage('Registration successful!');
end
else begin
reg.DeleteValue('SMS service');
ShowMessage('Delete successfully!')
end;
Reg.CloseKey; //Close key
finally
Reg.Free;
end;
end;
example:
SetAutoRun(true); //Registration startup
SetAutoRun(false); //Delete startup