ISCL is a Intelligent Information Consulting System. Based on our knowledgebase, using AI tools such as CHATGPT, Customers could customize the information according to their needs, So as to achieve

Making an application restart with Windows

1
When you shut Windows with Windows Explorer still running, the next time Windows comes up, the Win Explorer restart as well. You may wish your application to exhibit the same behavior.
Below you'll find a code extract from a (main) form unit with the desired behavior:

~~~~~~~~~~~~~~~~~~~~~~~~~
type
   TForm1 = class(TForm)
     ...
   public
     procedure WMEndSession(var Msg: TWMEndSession) ;
       message wm_EndSession;
   end;
...

uses
   Registry;
...
procedure TForm1.WMEndSession(var Msg: TWMEndSession) ;
const
   Restart =
'Software\Microsoft\Windows\CurrentVersion\RunOnce';
begin
  if Msg.EndSession then
  begin
   with TRegistry.Create do
    try
     RootKey := HKEY_LOCAL_MACHINE;
     if OpenKey(Restart, True) then
       WriteString
         (Application.Title, CmdLine)
    finally
     Free
    end;
   Msg.Result := 0
  end;
  inherited;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Case statement that *accepts* string values
« Two (or more) line Hint box

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.