Is application running ?

In post-DOS Oss it’s possible running multiple applications, even multiple instance of same application simultaneously. Sometime running multiple instance of same application may cause unpredictable results. So requires impeding, For this purpose HMG offers SET MULTIPLE ON | OFF [WARNING] command which impedes (OFF) or allow (ON) attempts to run multiple instances of the application with optional warning for both situation.

Sometime may be requires decide to allowing at run time. In this case you need know either a running instance exist or not before allowing or impeding.

IsAppRunning() function is for help this situation.

#include <>


   LOCAL cCurrApp := HB_ProgName()
   IF IsAppRunning( cCurrApp )
      MsgSTop( cCurrApp + CRLF + CRLF +;
               "Application is running already !", "Error")
      DEFINE WINDOW frmIsAppRunTest ;
         ROW 0 ;
         COL 0 ;
         WIDTH 650 ;
         HEIGHT 450 ;
         TITLE "Testing 'IsAppRunning()' function" ;
         ON INIT MsgInfo( cCurrApp + CRLF + CRLF + ;
                          "Application is running for first time !",;
                          "No problem") ;
         ON KEY ESCAPE ACTION ThisWindow.Release
      END WINDOW // frmIsAppRunTest


RETURN // IsAppRunTest.Main()      


PROCEDURE IsAppRunning(;
                        cAppName )

   LOCAL aProcess := EnumProcessesID(),;      // --> return array { nProcessID1, nProcessID2, ... }      
         nInstance := 0,;
         lRVal := .F.
   FOR EACH n1ProcID IN aProcess 
      IF cAppName == GetProcessFullName( n1ProcID ) 
         IF ++nInstance > 1
            lRVal := .T.
   NEXT n1ProcID
RETURN lRVal // IsAppRunning()


One response to “Is application running ?

  1. Pingback: HMG Samples | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.