Page 1 of 1

How prevent running an application twice ?

Posted: Wed Feb 21, 2007 1:00 am
by driessen
Hello,

A FW16 application can't be run twice on a PC, unless it is run in different parts of the memories (properties of shortcut).

How can I prevent that a FW32 application is run twice ?

Thanks.

Michel

Posted: Wed Feb 21, 2007 4:12 am
by techops
there is a tmutex class from fivewin.info (Patrick Mast) you should look at

Posted: Wed Feb 21, 2007 7:53 am
by Antonio Linares

Code: Select all

#include "FiveWin.ch" 

#define GW_CHILD      5 
#define GW_HWNDNEXT   2 

function Main() 

   local oWnd 
    
   if Is Exe Running( cFileName( HB_ARGV( 0 ) ) ) 
      ShowApplication() 
   else    
      DEFINE WINDOW oWnd TITLE "Test" 
    
      ACTIVATE WINDOW oWnd 
   endif    
    
return nil    

function ShowApplication() 

   local hWnd := FindWnd( cFileNoExt( HB_ARGV( 0 ) ) ) 
    
   if hWnd != nil 
      SetForeGroundWindow( hWnd ) 
   endif    
    
return nil    

function FindWnd( cTitle ) 

   local hWnd := GetWindow( GetDesktopWindow(), GW_CHILD ) 

   while hWnd != 0 
      if Upper( cTitle ) $ Upper( GetWindowText( hWnd ) ) 
         return hWnd 
      endif 

      hWnd = GetWindow( hWnd, GW_HWNDNEXT ) 
   end 

return nil 

Posted: Wed Feb 21, 2007 8:37 am
by Enrico Maria Giordano
Antonio Linares wrote:

Code: Select all

if Is Exe Running( cFileName( HB_ARGV( 0 ) ) )
IsExeRunning() :-)

EMG

Posted: Wed Feb 21, 2007 1:36 pm
by driessen
Thanks guys.

You were a great help.

My questions has been answered greatfully.

Regards,

Michel

Posted: Wed Feb 21, 2007 4:37 pm
by James Bott
If I remember correctly, isExeRunning() doesn't work with MDI apps when there is at least on child window open (since the main window title changes) and it can also fail to work properly if there is a folder of the same name open.

James

Posted: Fri Mar 02, 2007 5:55 am
by yam_hiong
I'm using this code because sometimes HB_ARGV(0) acts weird on some computers, ie. slow start, my app can run twice, etc.

Code: Select all

IF IsExeRunning(cFileName(GetModuleFileName(GetInstance())))   //cFileName(HB_ARGV(0))
   msgalert("Program already running!"+CRLF+"This program cannot be started more than one instance!")
   QUIT
ENDIF