Tobia
Tobia

Reputation: 9524

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?

Upvotes: 4

Views: 1818

Answers (2)

TLama
TLama

Reputation: 76713

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

Upvotes: 4

Andy
Andy

Reputation: 646

In Inno Setup's [Setup] section:

AppMutex=[mutex name]

In Class section of application's main form (outside of form_Load):

Dim mutex As New System.Threading.Mutex(False, "[mutex name]")

(note this is in vb, not c#)

Upvotes: 0

Related Questions