How can I do this one?
For some reason or selected by the user, “ask” the current application to restart it self.
uses ShellAPI;
...
procedure TForm1.RestartThisApp;
begin
ShellExecute(Handle, nil, PChar(Application.ExeName), nil, nil, SW_SHOWNORMAL);
Application.Terminate; // or, if this is the main form, simply Close;
end;
There is another way for closing-restarting the application:
Save a scheduled task to a short time after the application closes. This will have to be the VERY LAST thing your application does before exiting (no further data processing, saving, uploading or whatever)
eg.
When your program starts again, it should check for any such scheduled task and remove them. This must be the VERY FIRST action your application should do when starting. (cleanup)
AFAIK, The Delphi Jedi component set has a component you can do the task scheduling stuff with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With