• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4171
  • Last Modified:

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
0
SpringMVC
Asked:
SpringMVC
  • 4
  • 2
1 Solution
 
mirtheilCommented:
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

0
 
SpringMVCAuthor Commented:
That's certainly helpful. But if program changes title(and that's my case) during the work - this method won't be working :(
0
 
gskoczylasSenior Software DeveloperCommented:
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.
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
SpringMVCAuthor Commented:
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".
0
 
gskoczylasSenior Software DeveloperCommented:
So you can create Mutex with some constant name + folder's name.
0
 
SpringMVCAuthor Commented:
Hm.. That's also an option :) I'll consider that. Tnx
0
 
SpringMVCAuthor Commented:
Good solution.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now