Time passes and with it we finish maturing the ideas, the techniques employed.

The example of using wapi_CreateMutex and IsExeRunning is pretty much the same.
The only difference I see is that one is called by the function in Harbour and the other by a function in C in the HMG.
Both in my opinion are expendable for practical use.

In my opinion, it does not make sense to check if the application is already running without taking such a limited action as telling the user that the application is already running only.

IsExeRunning function in HMG IMHO can be improved by adding a optional parameter that indicates if it wants to return the handle of the window that was already running. This way we could bring forward the window by restoring and making focus, after then to close the second instance.

It can even remains minimized and use FlashWindowEx function if we so desire.

I have prepared this example by comparing 4 options for your evaluation and who knows if the idea could be improved or at least be adopted for HMG:

<Attached files was removed because there is a newest version more ahead of this same topic>

What do you think ? (Run twice each option and compare)

Could you give me your opinion, which option would be most convenient to use ?

Sorry I forgot to attach Demo6.fmg file. It's a simple form and without window's title.

I've adapted the new IsExeRunning2 function to keep retrocompatibility with the current IsExeRunning function. Returning as default, logical value if the current application is already being run in another instance. And when the second parameter was passed, it would return the handle of the instance that was already open.

In that way, we would have a IsExeRunning function improved by IsExeRunning2.
Improved in my criteria for these reasons:

In the same way as IsExeRunning, IsExeRunning2 function does not need SET MULTIPLE OFF.

IsExeRunning2 function works with full name of application. What means that application's full path is being included and it's what ensures that will not confuses with other application with the same name to be different one.
For example: If app with location+name C:\App1\Demo.exe is running and in another instance (other session) other app with location+name C:\App2\Demo.exe be in trying to run... certainly it will be guaranteed. Because this last application even that is with same names are also at different places.

The IsExeRunning2 function is able to return a preexisting instance identifier of the same application. Behaving differently than IsExeRunning if informed .T. As new and second parameter.
This will allow the programmer to use the handle of the pre-existing instance and manipulate the focus resumption. If the window is minimized, it would restore it and bring it to the front for focus. If the other instance is behind you would only bring it forward and focus.

Keep retrocompatibility with the pre-existing IsExeRunning function in HMG.

Continuing to answer your questions Serge...

And how about killing the running EXE?

You do not have to kill any process. Just check if it has another session running this same application.
If it is, it only exits (it exits with RETURN) and if not it finds: it continues the application normally.

In case the program got hung up (infinite loop or something)

If got hung up, systems should start again. Because this function is not tied to any temporary file (as it has proposed or indicated by Carlos RD).IsExeRunning2 it is similar in the aspect of checking app running names. But improved in the way it's done.

Case 3 is best option but then it will bring you back to the EXE you can't get to stop or rerun.

Yes, you will decide what to do if other session is in running in duplication...

Please note that this Demo6 minimizes the window just to simulate that the user left it minimized and tried twice open the app.

Could you do me the favor of moving my messages from this topic and Serge's last ones (if he does not show discomfort).
I did not note it was in the Spanish session and would like it to be part of a new topic in "HMG Tutorials and Tips".
I then add in the topic in Spanish a message indicating the link of my new indications.
I want to do this on the grounds that I want something more generalized (Mostly by the title. It's also wrongly write in spanish too) and because I consider that I have not expressed myself in Spanish what I prefer to do in the Spanish section.

I appreciate your providence in advance.
I intend to use this same message by re-editing and to indicate a new link for the new topic in Spanish language.

Sorry for the inconvenience.

HMGing a better world"Matter tells space how to curve, space tells matter how to move."Albert Einstein