Loading
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.

  • 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.
  • Community Manager (Flexera Software)

    If nothing else, if the C++ code is working, you could build it into a DLL and call that from InstallScript...
  • Community Manager (Flexera Software)

    But for what it's worth, I've had luck with code like this (waiting for an MSI's Execute sequence to finish):prototype Kernel32.OpenMutex(NUMBER, BOOL, BYVAL STRING);

     

    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;
    Expand Post
  • I've had good success with the function available at installsite.org: InstallScript samples > External programs and shell > List and Shut Down Running Applications.

     

    It has a function that detects and another that shuts down.
  • " Christopher Painter wrote:

     

    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.
    Expand Post
  • " RobertDickau wrote:

     

    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.
    Expand Post
  • Not needed. Type 1 CA's stored in the binary table automatically get streamed to a temp file for execution by Windows Installer.

Loading
How to detect running application using CreateMutex() ???