2

I am running a c# application and I need to know whether Apache Tomcat is running or not and also know the port for it.

There are multiple ways Tomcat is installed. In certain installations, I get the service in the Services list while in some I do not.

Can somebody help me?

Kangkan
  • 15,267
  • 10
  • 70
  • 113

1 Answers1

0

You could use something like Process.GetProcesses from System.Diagnostics;

Process[] processlist = Process.GetProcesses(); 

and check for the relevant process name in that list. Otherwise look at some answers of the related links to find a specific process name (ie. Tomcat).

For finding the port, this might be a little harder programatically. You might have to parse Tomcat's configuration file $CATALINA_HOME/conf/server.xml to find the ports in use. You'd be looking for something like;

<Connector port="{portNumber is here}"...

Take a look at the Tomcat documentation regarding the configuration files.

Community
  • 1
  • 1
Mr Moose
  • 5,946
  • 7
  • 34
  • 69
  • The process name is not "Tomcat", but it is "Java" and the attribute "MainWindowName" is "Tomcat". I am using a combination of getting the services and processes to know whether Tomcat is running or not and reading the port from the config file. But I wanted to do it without reading the config. – Kangkan Feb 10 '12 at 08:25
  • 1
    You could use PortReporter - http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=9964 as an alternative to scanning the config files. – Mr Moose Feb 10 '12 at 23:22