- NSIS Discussion
- problem with OpenMutexA (getting result).
Archive: problem with OpenMutexA (getting result).
MVI
30th March 2007 11:18 UTC
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...
Red Wine
30th March 2007 13:02 UTC
If your app is the running installer, take a look here,
http://nsis.sourceforge.net/Allow_on...aller_instance
MVI
30th March 2007 13:53 UTC
My app not an installer. And I've already saw that code. But my question not about it...
Red Wine
30th March 2007 14:04 UTC
Then, perhaps you might want to take a look on this,
http://nsis.sourceforge.net/FindProcDLL_plug-in
MVI
30th March 2007 14:35 UTC
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...
Anders
30th March 2007 14:37 UTC
Your quotes are messed up, escape " or use '
System
::Call'kernel32::CreateMutexA(...t"foo")?e'
MVI
30th March 2007 15:07 UTC
in second and third examles of http://nsis.sourceforge.net/Allow_on...aller_instance used double-quotes...
also i've tried and nothing changed...
Comm@nder21
30th March 2007 19:10 UTC
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'
MVI
2nd April 2007 09:02 UTC
I'm actually need help with my first "code"...
There are single quotes and there is output argument....
kichik
2nd April 2007 11:21 UTC
And what's the code you've used in your application?
MVI
2nd April 2007 12:15 UTC
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);
}
Comm@nder21
2nd April 2007 19:04 UTC
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)
MVI
3rd April 2007 08:44 UTC
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...
kichik
3rd April 2007 09:14 UTC
The error value goes into $1 but you check $R1. Check $1 or change r1 to R1.
MVI
3rd April 2007 09:26 UTC
thanks. now it works.