views:

91

answers:

2

For a windows script I am writing, I need to detect if the machine has Apache 2.2 installed, and to find the application path.

One solution I came up with is to wget http://localhost:8080/server-info and parse the root and the config file from it. This would fail if the server does not use port 8080

Another option would be to call “sc qc Apache2.2” and to parse the returning string. This would fail if the server is not installed as a service, or is using a different name.

Is there any better way to do that?

A: 

As I recall, Apache writes some registry keys. If you know how to read them from a script, that might help.

R. Bemrose
+2  A: 

Not a lot of great options if they didn't install it using the installer. If they used the MSI/installer, you can check the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Apache\2.2.2\ServerRoot 
HKEY_CURRENT_USER\SOFTWARE\Apache Software Foundation\Apache\2.2.2\ServerRoot

You can also check the running process list:

WMIC PROCESS get Caption,Commandline,Processid

Look for the appropriate EXE. If for some reason you needed the port number, then use netstat and search for the appropriate port.

Also, when you say "a windows script", I am assuming you are using something modern and capable like Windows Scripting Host (my favorite) or PowerShell. Don't even bother with batch files.

James Schek