Can java find out if a windows service is installed?

Does anybody know if there is a simple way for a java program to find out if a named service is installed on windows?

We are using JavaService (http://multiplan.co.uk/software/javaservice) to wrap a java program to run as a windows service and that works just fine.

Now we have another java program which installs, uninstalls, starts and stops this service which also works just fine,except it cant tell if the service has already been installed (and is not running).

I've seen a solution which parses the output of sc.exe and looks for a status string, but I'm worried that could easily break and I'm sure that it wont work on a non-english installation. What I'd like is a pure Java API solution.

If JNI is the only way, Id rather not write it myself, so can anyone recommend an open source existing solution?

We are using java 1.5 on windows xp.

Thanks in advance.

Philip Wilkinson.

[948 byte] By [wilkinpa] at [2007-11-26 21:54:28]
# 1

> What I'd like is

> a pure Java API solution.

>

That isn't going to happen. It is OS specific.

> If JNI is the only way, Id rather not write it

> myself, so can anyone recommend an open source

> existing solution?

>

You could probably use a command line tool.

jschella at 2007-7-10 3:49:21 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Yep, use a command line tool:

1. Invoke eg psservice.exe from Mark Russinovich excellent pstools package from java

2. Read the reply of the command using an inputstream

3. Parse the stream, to check whether your service is running

Example (not tested, but pretty darn close :-) ):

InputStream is = Runtime.getRuntime().exec("psservice.exe").getInputStream();

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader(isr);

String line;

while ((line = br.readLine()) != null)

System.out.println(line);

br.close();

isr.close();

is.close();

yaketea at 2007-7-10 3:49:21 > top of Java-index,Java HotSpot Virtual Machine,Specifications...