you either have to enumerate all windows which will give you visible running apps, or you have to enumerate all processes which is more detailed but more difficult to do (in some respects) and some of the process names aren't indicative of the parent application that process belongs too.
There are several components out there (check DSP) which make it easy to do it either way
By using API calls (their easy, just add ShellAPI to your uses clause) the following will work...
{ attempt to create a named nutex }
CreateMutex(Nil,False,'AppName');
{ check to see if it was created }
if ( GetLastError = ERROR_ALREADY_EXISTS ) then begin
{ inform the user only one instance is allowed }
MessageDlg('App is already running...' + CHR(10) +
'Shutting down ',mtError,[mbOk],0);
{ send a broadcast message to all windows, your app will recognize it and show itself }
SendMessage(HWND_BROADCAST,RegisterWindowMessage('AppName'),0,0);
Application.Terminate;
end;
Just change 'AppName' to your applications name - found in Project, Options, Application, Title.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.