This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: How to detect running application using CreateMutex() ???
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 24, 2007
02:59 AM
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 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.
(9) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 24, 2007
08:29 PM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 25, 2007
07:29 PM
If nothing else, if the C++ code is working, you could build it into a DLL and call that from InstallScript...
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 25, 2007
07:46 PM
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;
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 27, 2007
09:23 AM
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.
It has a function that detects and another that shuts down.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 27, 2007
09:35 AM
And if you know a particular executable file name, Is(FILE_LOCKED, "W:\\here\\file\\is.exe") can help.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 27, 2007
01:31 PM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 27, 2007
01:34 PM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 27, 2007
01:41 PM
Not needed. Type 1 CA's stored in the binary table automatically get streamed to a temp file for execution by Windows Installer.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Sep 04, 2007
01:54 AM
Using Is(FILE_LOCKED, "FILE PATH")
Thanks, Robert! 🙂
Thanks, Robert! 🙂
![](/skins/images/3B39CE851FDD5528C393F146EB70A2D0/responsive_peak/images/icon_anonymous_message.png)