Tobia Tobia -4 years ago 234
C# Question

AppMutex doesn't work on Inno Setup

Seems that

AppMutex
directive doesn't work for my installation script.
I follow this articles: http://www.jmedved.com/2012/06/mutex-for-innosetup/

This is my C# code of my application:

private static string appGuid = "Loader";
...
bool createdNew;
var mutexSec = new MutexSecurity();
mutexSec.AddAccessRule(
new MutexAccessRule(
new SecurityIdentifier(WellKnownSidType.WorldSid, null),
MutexRights.FullControl, AccessControlType.Allow));

using (var setupMutex = new Mutex(false, @"Global\"+appGuid, out createdNew, mutexSec))
{
if (!createdNew)
{
MessageBox.Show(
"Application already running.", "Loader", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Loader(args));
}


In Inno Setup script i just have:

AppMutex=Loader


However the installer could run also if the application is running.

I also tried to check if there really was the mutex, so with process explorer I looked for application handlers and i get this:

AppMutex=Loader

Mutant \BaseNamedObjects\Loader


What I miss?

Answer Source

Since you've created mutex in the Global\ namespace in your application, you should explicitly do the same also for the AppMutex mutex name in your Inno Setup script, since mutex objects are not created in global namespace if you omit namespace prefix. So using this script line should fix your problem:

[Setup]
AppMutex=Global\Loader
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download