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 <hmg.ch> PROCEDURE Main() LOCAL cCurrApp := HB_ProgName() IF IsAppRunning( cCurrApp ) MsgSTop( cCurrApp + CRLF + CRLF +; "Application is running already !", "Error") ELSE 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") ; MAIN ON KEY ESCAPE ACTION ThisWindow.Release END WINDOW // frmIsAppRunTest frmIsAppRunTest.Center() frmIsAppRunTest.Activate() ENDIF RETURN // IsAppRunTest.Main() *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._. PROCEDURE IsAppRunning(; cAppName ) LOCAL aProcess := EnumProcessesID(),; // --> return array { nProcessID1, nProcessID2, ... } nInstance := 0,; n1ProcID,; lRVal := .F. FOR EACH n1ProcID IN aProcess IF cAppName == GetProcessFullName( n1ProcID ) IF ++nInstance > 1 lRVal := .T. EXIT ENDIF ENDIF NEXT n1ProcID RETURN lRVal // IsAppRunning() *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.