You can cheat and use CreateMutex:

Replace "MyAppNameString" with a string identifier that's unlikely to be
used by someone elses app.

== c0de ==

procedure AppStartup;
var
  Mutex: THandle;
begin
  Mutex := CreateMutex(NIL, False, 'MyAppNameString');
  if WaitForSingleObject(Mutex, 100) = WAIT_TIMEOUT then
  begin
    ShowMessage('App is already running on this computer.');
    Application.Terminate
  end;
end;

== /c0de ==

========================================================
 Luke Pascoe                          Delphi Programmer
             enSynergy Consulting LTD

 [EMAIL PROTECTED]  +64-9-3551593  fax +64-9-3551590
 Level 4,   10-12 Federal St,   Auckland,   New Zealand
 PO Box 32521,  Devonport,  Auckland 1330,  New Zealand

================== I.H.T.F.P. ==========================


> -----Original Message-----
> From: Colin Fraser [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, 19 June 2001 4:38 p.m.
> To: Multiple recipients of list delphi
> Subject: [DUG]: Run Once Code
> 
> 
> Hi,
> 
> Does anyone have handy any code that will stop an application 
> running more
> than once instance...
> 
> I know there are some components around that you can just 
> dump on the main
> form, but what I am after is to programmatically control how 
> the app starts.
> 
> For example, if there is a certain command line parameter 
> then start a new
> instance, otherwise bring the new instance to the front and 
> process the new
> command line parameters.
> 
> Regards
> 
> Colin
> 
> 
> ######################################################################
> Attention:
> The information in this email and in any attachments is 
> confidential.  
> If you are not the intended recipient then please do not distribute, 
> copy or use this information. Please notify us immediately by return 
> email and then delete the message from your computer.
> Any views or opinions presented are solely those of the author.
> ######################################################################
> --------------------------------------------------------------
> -------------
>     New Zealand Delphi Users group - Delphi List - 
> [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED] 
> with body of "unsubscribe delphi"
> 
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to