manju
manju

Reputation: 3

Check if application is running or not

I am using innosetup to create installation for my windows application. Before starting installation i need to check whether application is already running or not. I have used the following code, which is not working properly.

const
WM_CLOSE = 16;

Function InitializeSetup : Boolean;
var winHwnd: longint;
    retVal : boolean;
    strProg: string;
begin
  Result := true;
  try
    strProg := 'myApp.exe';
    winHwnd := FindWindowByWindowName(strProg);
    Log('winHwnd: ' + inttostr(winHwnd));
    if winHwnd <> 0 then
      retVal:=postmessage(winHwnd,WM_CLOSE,0,0);
      if retVal then begin
        MsgBox('Window is  not running', mbInformation, MB_OK);
        Result := True
        end
      else begin
       MsgBox('Window still open', mbInformation, MB_OK);
        Result := False;
 end;
  except
  end;

end;

Here winHwnd is always comes as 0. Please let me know what's wrong with this code.

Thanks, Manju

Upvotes: 0

Views: 1257

Answers (1)

Otherside
Otherside

Reputation: 2855

InnoSetup has a built-in check to see if your application is running, look at the AppMutex setting in the [Setup] section. All you need to do is create a named mutex in your application, and specify the name of that mutex in your innosetup script. InnoSetup will then do the check and display a message itself.

Upvotes: 1

Related Questions