Archive: problem with OpenMutexA (getting result).


problem with OpenMutexA (getting result).
Greetings...

By the following code:


MessageBox MB_OK "TEST"

CheckApp:
System::Call 'kernel32::OpenMutexA(i 0, i 0, t "{D50A79A4-CFD5-49a0-B94E-BBFA1D974616}") i .r1'
IntCmp $R1 0 +3
MessageBox MB_OK "App is running."
GoTo CheckApp

i'm trying to check if my app. is running.
But I can't see any "App is running." MessageBoxes...
(App is running and it has mutex with such name. I can see "TEST" MessageBox.)

What I'm doing wrong?

Best regards...

If your app is the running installer, take a look here,

http://nsis.sourceforge.net/Allow_on...aller_instance


My app not an installer. And I've already saw that code. But my question not about it...


Then, perhaps you might want to take a look on this,

http://nsis.sourceforge.net/FindProcDLL_plug-in


Thats completely nothing of the kind I neded...
All that I need, is just point on my error (with correction).
For example this:


CheckForApp:
System::Call "kernel32::CreateMutexA(i 0, i 0, t "{B1454C40-EAFE-4124-809F-90DEC53E06EC}") ?e"
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK "Please close App before continue."
GoTo CheckForApp

code (changed from http://nsis.sourceforge.net/Allow_on...aller_instance)
Always shows "Please close App before continue." independently of test application presence...

Your quotes are messed up, escape " or use '

System::Call'kernel32::CreateMutexA(...t"foo")?e'


in second and third examles of http://nsis.sourceforge.net/Allow_on...aller_instance used double-quotes...
also i've tried and nothing changed...


1. you'll need to use the different quotes.

2. you missed to specify an output argument:

System::Call 'kernel32::CreateMutexA(i 0, i 0, t "{B1454C40-EAFE-4124-809F-90DEC53E06EC}") i .n ?e'


I'm actually need help with my first "code"...
There are single quotes and there is output argument....


And what's the code you've used in your application?


I've created two applications.
One, fore creating mutex:

        HANDLE mutex = ::CreateMutex(NULL, TRUE, L"{B1454C40-EAFE-4124-809F-90DEC53E06EC}");
while (1)
Sleep(1000);

and one, for check this mutex:
        while (1)
{
HANDLE mutex = ::OpenMutex(READ_CONTROL, FALSE, L"{B1454C40-EAFE-4124-809F-90DEC53E06EC}");
if (mutex != 0)
{
CloseHandle(mutex);

MessageBox(NULL, L"Please close App before continue.", NULL, MB_OK);
}
else
Sleep(1000);
}

if you got problems with your first code, it's missing the error output:

System::Call 'kernel32::OpenMutexA(i 0, i 0, t "{D50A79A4-CFD5-49a0-B94E-BBFA1D974616}") i .r1'
you need the ?e at the end, because r1 won't tell you anything about the mutex. only the call of GetErrorSomethingBla which is done by ?e will give you the info whether the mutex could have been created or not.


use the code i submitted previously and it will work (i'm using it all the time with my codes)

I've changed my code:

        CheckForApp:
System::Call 'kernel32::OpenMutexA(i 0x00020000, i 0, t "{B1454C40-EAFE-4124-809F-90DEC53E06EC}") i .r1 ?e'
StrCmp $R1 0 AppNotRunning
MessageBox MB_OK "Please close App before continue."
GoTo CheckForApp
AppNotRunning:

but MessageBox appears independently of mutex presence...

The error value goes into $1 but you check $R1. Check $1 or change r1 to R1.


thanks. now it works.