
ritulranjan1.5524915726066968E12 asked a question.
How to detect running application using CreateMutex() ???
Hi,
I am trying to detect if an application is currently running, through the mutex created by that application.
Following is the Installscript code I am using:
function OnBegin()
BOOL bReturn;
NUMBER nError, hMutex;
begin
hMutex = Kernel32.CreateMutex(NULL, FALSE, "MY_TEST_MUTEX");
nError = GetLastError();
if (hMutex != 0 && nError == 183) then
MessageBox("MY_TEST_MUTEX found, TestApp running!", 0);
endif;
if (hMutex != 0) then
Kernel32.CloseHandle(hMutex);
endif;
end;
However, the code doesn't really seem to help. The mutex always gets created. Using "global mutexes" (e.g. "Global\\MY_TEST_MUTEX") also doen't help. Interestingly enough, the equivalent C++ code works fine!
Any ideas why its not working? Am I doing something wrong here?
regards,
RR.
prototype Kernel32.WaitForSingleObject(HWND, NUMBER);
prototype Kernel32.ReleaseMutex(HWND);
function OnBegin( )
HWND hMutex;
NUMBER result;
begin
hMutex = OpenMutex(READ_CONTROL | SYNCHRONIZE, FALSE, "_MSIExecute");
if (hMutex) then
MessageBox("Found it!", INFORMATION);
result = WaitForSingleObject(hMutex, INFINITE);
if (result==0) then
MessageBox("Done!", INFORMATION);
ReleaseMutex(hMutex);
endif;
else
MessageBox("Can't find it!", WARNING);
endif;
end;
It has a function that detects and another that shuts down.
I'm not really sure, I haven't coded a mutex since the IS5 days. I'd step through the debugger to see if a handle is being created and/or what nError is being set to. "
Hi Christopher,
Well, I did step through the debugger; the conclusion being - the mutex/handle gets created and nError remains ZERO.
If nothing else, if the C++ code is working, you could build it into a DLL and call that from InstallScript... "
Ok, but if I make the DLL, shouldn't I take care of deploying it to some temporary location so that it can be used by InstallShield during run-time?
Pardon me, I am a little new to IS.
Thanks, Robert! :)