Board index » delphi » Checking for another instance of app?

Checking for another instance of app?

When my Delphi application starts up, how can I check if another
instance of my app is already running? I would like to have
only one instance at a time.

Thanks in advance,



Re:Checking for another instance of app?

HI there,

You could do two things (both are done in your Project source *before*
any createForm calls, etc - i.e. right after the initial BEGIN):

1) Check the value of HPrevInst (see the Help file for info):


   if HPrevInst <> 0 then

2) If your application has a *unique* Window Title, and you want to be
"fancy" ;-), you could pop up the active copy of your program:

    Wnd: HWnd;


   Wnd:=FindWindow(nil,"My Unique Window Title");
   if Wnd <> 0 then
       if IsEnabled(Wnd) then
         if IsIconic(Wnd) then


Hope this helps...

G.--- _Snappy_

Other Threads