Restart Delphi Application Programmatically

Posted by Smasher on Stack Overflow See other posts from Stack Overflow or by Smasher
Published on 2010-12-21T10:26:41Z Indexed on 2010/12/21 10:54 UTC
Read the original article Hit count: 282

It should not be possible to run multiple instances of my application. Therefore the project source contains:

CreateMutex (nil, False, PChar (ID));
if (GetLastError = ERROR_ALREADY_EXISTS) then
  Halt;

Now I want to restart my application programmatically. The usual way would be:

AppName := PChar(Application.ExeName) ;
ShellExecute(Handle,'open', AppName, nil, nil, SW_SHOWNORMAL) ;
Application.Terminate;

But this won't work in my case because of the mutex. Even if I release the mutex before starting the second instace it won't work because shutdown takes some time and two instance cannot run in parallel (because of common resources and other effects).

Is there a way to restart an application with such characteristics? (If possible without an additional executable)

Thanks in advance.

© Stack Overflow or respective owner

Related posts about delphi

Related posts about delphi-2010