0

At the very beginning of the script I have these lines of code:

#define ISSI_Splash "C:\InnoSetupProject\Images\client.bmp"                    
#define ISSI_Splash_T 3                                                                         
#define ISSI_Splash_X 500                                                                       
#define ISSI_Splash_Y 220

In my [Setup] section I add the directive:

AppMutex=ABClientLaunchMutex

Then in the [Code] section I create the mutex:

[Code]
function ISSI_InitializeSetup : Boolean;
begin
  Result := True;
  CreateMutex('ABClientLaunchMutex');
end;

#define ISSI_InitializeSetup

and those 2 lines of code are at the end of the script:

#define ISSI_IncludePath "C:\ISSI" 
#include ISSI_IncludePath+"\_issi.isi"

But this does not work as one would expect. Whenever I launch the installer it immediately shows me the mutex's message that my apllication is already running, but this is not true. I haven't created my mutex in the Global namespace, so I don't need to use the Global\ prefix. If I comment those 4 #define directives at the beginning then the mutex won't work at all.
Could you please tell me what is wrong with my code so it works like that?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
JConstantine
  • 1,020
  • 7
  • 19
  • 1
    Your code does exactly what you coded. You create `ABClientLaunchMutex` mutex in `InitializeSetup`. And then you ask Inno Setup not to continue when `ABClientLaunchMutex` mutex exists. So it never continues. – This looks like [XY problem](https://meta.stackexchange.com/q/66377/218578). – You better ask a question about what you want to implement, rather than about your wrong code that tries to implement it. – Martin Prikryl Mar 31 '20 at 15:30
  • I just want the setup application not to to install/uninstall the program is if it's already running and don't allow to run the seccond instance of that installer. I want to do that with mutexes if it's possible. – JConstantine Mar 31 '20 at 15:35
  • See [Inno Setup - prevent executing the installer multiple times simultaneously](https://stackoverflow.com/q/28628699/850848) – Martin Prikryl Mar 31 '20 at 15:44
  • @MartinPrikryl It's about the SetupMutex. And I need to use the AppMutex if want to prevent the installer from running if my application is already installed and launched. – JConstantine Mar 31 '20 at 15:51
  • For `AppMutex` you already have an answer: [Is it possible to check if program is already running before trying to install it? (Inno Setup)](https://stackoverflow.com/q/60526914/850848) – *"Your application must create the mutex for this to work"* – Martin Prikryl Mar 31 '20 at 20:36

1 Answers1

2

And I need to use the AppMutex if want to prevent the installer from running if my application is already installed and launched.

I think your mistake is that you are creating the mutex within the setup script itself when your application should be doing this.

I have AppMutex only once in my script:

[setup]
AppMutex=xxxyyyzzz

As the documentation states:

Use of this directive requires that you add code to your application which creates a mutex with the name you specify in this directive.

The documentation provides example. Here is how I do it with a Visual C++ MFC project:

BOOL CMeetingScheduleAssistantApp::InitInstance()
{
    CString strMutex;

    stMutex.LoadString(IDS_APP_MUTEX);

    m_hMutex = ::CreateMutex(nullptr, FALSE, strMutex);

    ...
    ...
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • What if I'm not allowed to modify the application code itself? Looks like I've misunderstood the very concept of those mutexes. I thought that I could it without modifying the app. – JConstantine Mar 31 '20 at 16:52
  • 1
    No. The whole concept is that your app runs and it says: hey this is my mutex. So when your setup runs it examines all running applications and checks their mutex. If it matches your then the setup etc stops. It must be created from within your app. – Andrew Truckle Mar 31 '20 at 16:57
  • 1
    It's all already in my answer to yours [Is it possible to check if program is already running before trying to install it? (Inno Setup)](https://stackoverflow.com/q/60526914/850848). – Martin Prikryl Mar 31 '20 at 19:47