I think I am not understanding the use of CreateMutex.
I want to prevent the starting of multiple uses of Explorer2.

Even though I have Explorer2 open, this code returns sucess.

Thanks.


.DATA

MutexString    db  "Explorer2.exe",0
Program_Running db  "Program is already running!!",0
Box            db  "Box",0

.CODE

Internal_Notes  db "A.K. 2010"

start:

; Use a Mutex, it can only be created once until released.
; If you create a mutex when your app starts any subsequent versions of your app
; that attempt to create the same mutex will fail to create a new one.
;
invoke CreateMutex,NULL,TRUE,ADDR MutexString
invoke GetLastError

.IF eax != 0

invoke MessageBox, 0, ADDR Program_Running, ADDR Box,MB_ICONINFORMATION

.endif

invoke ExitProcess,0


end start


Posted on 2010-05-13 10:20:19 by skywalker
CreateMutex

If the function succeeds, the return value is a handle to the newly created mutex object.

If the function fails, the return value is NULL



GetLastError

The return value is the calling thread's last-error code.


What do you check here:

.IF eax != 0
Posted on 2010-05-13 16:07:08 by JimmyClif
It does exactly with it is supposed to do.. I put that into a test app, ran it and tried to run another instance and got the message box...  Explorer2 is your program or another program?
Posted on 2010-05-13 16:10:36 by Gunner

CreateMutex

If the function succeeds, the return value is a handle to the newly created mutex object.

If the function fails, the return value is NULL


GetLastError

The return value is the calling thread's last-error code.


What do you check here:

.IF eax != 0


I think I understand what is going on.

It would work only if I try to start another explorer2 WITHIN my app.
Why I would try to start another mutex seems silly.

;  any subsequent versions of your app
; that attempt to create the same mutex
Posted on 2010-05-13 21:24:56 by skywalker

I think I understand what is going on.

It would work only if I try to start another explorer2 WITHIN my app.


mutex stands for MUTual EXclusion.

In the case of Windows and CreateMutex, the simplest (but perhaps not the best) way to conceptualize it, is as a system-wide uniquely named variable that any application can create/access... it either currently exists, or it doesn't.

If Explorer2 (perhaps you mean xplorer˛?) was never designed to rely on a particularly named mutex, then how can you expect the concept to be of any use outside of the program?


Why I would try to start another mutex seems silly.


The goal is not to "start" another mutex, it is to attempt to create the same uniquely named mutex, and fail if it already exists... thus satisfying mutual exclusion.

If you really want to pursue this, then you should do it in a manner that is on par with its usefulness... quick n' dirty, yet direct.

1.) Rename Explorer2.exe (or whatever the primary executable name is) to something else like Explorer2.run.exe.
2.) Take your mutex wrapper and rename it to Explorer2.exe, ensuring that it attempts to load Explorer2.run.exe if the mutex does not currently exist.
3.) Call it a day and move on to more useful things than trying to circumvent the design of an application.

I don't know if your wrapper program has to be constantly running to ensure that the mutex survives, as this changes the design requirements in case of crashes and whatnot, but I'm sure reading the MSDN documentation will answer that question.
Posted on 2010-05-13 23:48:40 by SpooK

If Explorer2 (perhaps you mean xplorer˛?) was never designed to rely on a particularly named mutex, then how can you expect the concept to be of any use outside of the program?


Explorer2 is a modified explorer.exe that is customized to show Go instead of Start.

Thanks for taking the mystery out of CreateMutex.

Take care.

Posted on 2010-05-14 06:56:50 by skywalker