Link to home
Start Free TrialLog in
Avatar of SpringMVC
SpringMVC

asked on

Inno Setup - Check if specific exe is running.

Hi.
I have inno setup script(in pascal), and I need to check before installation, if an application is running or not.
The problem is, that:
a) I can not use Mutex, because in my application mutex is created with name + version.
Inno Setup doesn't know particular version of the previously installed programm.
b) I can not use something like IsModuleLoaded('myapp.exe'), because
there could be two different programms with same exe name, but in different folders.
And setup must allow to install to folder A, then the program from folder B\myapp.exe is running.
Any help would be highly appreciated!
P.S Sorry for my english
Avatar of Mirtheil
Mirtheil
Flag of United States of America image

You could use something like FindWindowByWindowName and then issue a SendMessage with a WM_QUIT to close the application (or just abort the install after displaying a message.  Something like:

function InitializeSetup(): Boolean;
const 
   WM_QUIT = 18;
var 
   winHwnd: longint;
   retVal : boolean;
   strProg: string;
begin
 result:=true;
 try
   strProg := 'MyApplication.exe';
   winHwnd := FindWindowByWindowName(strProg);
   if winHwnd <> 0 then
     begin
      //retVal:=postmessage(winHwnd,WM_QUIT,0,0);
      //or
      //Display Message Box saying application is running
      // and close it, then exit setup by setting:
      //result:=false;      
 except
 end;
end;

Open in new window

Avatar of SpringMVC
SpringMVC

ASKER

That's certainly helpful. But if program changes title(and that's my case) during the work - this method won't be working :(
You can create additional mutex in your application. Mutex's name should be constant (without Version). Then you can use this mutex in the InnoSetup's script.
If I create a mutex, it would be impossible to run two same programs from two different folders.

I am currently searching for a solution, which checks running processes and checks their execution path. So if inno setup installs to "program files/A"
I need to check if a process "prog.exe" exists and if it exists, if it's execution path is "program files/A".
ASKER CERTIFIED SOLUTION
Avatar of gskoczylas
gskoczylas
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hm.. That's also an option :) I'll consider that. Tnx
Good solution.