1

Is there a foolproof way to detect using Inno Setup if Apache for Windows is installed on a computer? I'm using the Apache lounge version (https://www.apachelounge.com/download/) which doesn't have a built-in installer but it does install a specific service if needed.

I can search whether that Windows service is present on the machine, but I'm afraid that other Apache versions might install a different service or no service at all (but it may still be running in the background and interfering).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Steve
  • 2,510
  • 4
  • 34
  • 53
  • Why do you need that? What will you do with that information? – Martin Prikryl Dec 14 '18 at 20:33
  • I'm trying to make a foolproof installer that will install Apache, PHP and the scripts for my web app on a Windows server. In case Apache is alredy installed, it shouldn't install itself (not to mess with the existing installation). – Steve Dec 15 '18 at 10:38
  • OK, but if you are going to install PHP to Apache, you need to modify its configuration file, right? So it's not only detection whether Apache is installed, but where is it installed to and where its configuration file is. – Martin Prikryl Dec 15 '18 at 11:26
  • If it's installed, I don't want to install, because I want an exclusive copy of Apache. There shouldn't be anything else running using Apache. So I just want to check if Apache is already installed, and if it is, then deny the installation. (we aren't talking about big servers but servers of small businesses that shouldn't be running anything else but this program). – Steve Dec 15 '18 at 21:17
  • What about checking for any process whose name contains "apache"? – Martin Prikryl Dec 15 '18 at 21:29
  • Sounds like a good idea. How do I go about that in Inno? If Apache is running as a service, will it show up among the processes (and not just separately, as a service)? – Steve Dec 16 '18 at 01:15

1 Answers1

0

You can check for any running process whose name includes "apache" keyword (even services are processes).

You can use the code from this answer:
How to check with Inno Setup, if a process is running at a Windows 2008 R2 64bit?

Just replace the query with:

Format('SELECT Name FROM Win32_Process Where Name like "%%%s%%"', [FileName])

And then you can use it like:

function InitializeSetup(): Boolean;
begin
  Result := True;
  if IsAppRunning('apache') then
  begin
    MsgBox('Apache is installed and running, cannot proceed.', mbError, MB_OK);
    Result := False;
  end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992