Locate the path of an Apache server on windows

By : Raz
Source: Stackoverflow.com
Question!

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?

By : Raz


Answers

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.



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

By : Powerlord


This fellow shows sample code if you still want to do it after all the caveats:

protected void EditConfigButton(object sender, EventArgs e)
{
   Configuration objConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
   AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings");
   //Edit
   if (objAppsettings != null)
   {
      objAppsettings.Settings["test"].Value = "newvalueFromCode";
      objConfig.Save();
   }
}

One valid reason for editing a web.config is to encrypt it, which is what that article is about.

By : DOK


This video can help you solving your question :)
By: admin