Monitoring windows services (and others)

Hi,

I am just developing a small, modular monitoring utility, to remotly monitor specific computers on software crashes. Now I would like to code a module, that watches windows services. Are there any classes useful for this? There are a lot of programms listing service status remotely, but I found no useful documentation how they do so, and no (java) source code, that I could adept or at least unterstand. Any tips?

Thanks,

Rolf

[457 byte] By [Pirf2a] at [2007-10-2 0:18:41]
# 1

Those types of programs are hybrids. They use JNI to work.

JNI, for those that don't know, is Java Native Interface. It allows a Java programmer to use platform-native code libraries such as C++ libraries that can access native Windows components, and then interact with their Java class objects.

watertownjordana at 2007-7-15 16:20:11 > top of Java-index,Archived Forums,Socket Programming...
# 2

What I would like to do, is monitoring those services remotly. Since there are Non-Java-programs, that do so without installing any software on the target PC, and java has also various classes available to access the local network interface (send specific packages etc.), I hoped, this would be possible, without platform specific code.

My problem is, that I have no idea about what this packages look like. What protocol they use, what port they access, what request they contain and what response they should cause. This maybe a question, that I should better ask in a windows-forum, but I still found out nothing about it. :-(

Pirf2a at 2007-7-15 16:20:11 > top of Java-index,Archived Forums,Socket Programming...
# 3

I have actually done the same myself. I let a windows java-application run on a remote computer, and connected to it with Sockets. The remote application could then query the service states of the local computer.

I used PSTools http://www.sysinternals.com/Utilities/PsTools.html (free) for this purpose. The code is ugly but worked. You need to use Runtime.exec launching psservice and then parse the output with Process.getInputStream. Since you are bound to windows-NT platform (which services are), this should not be any problem.

Example:

Pattern pattern = Pattern.compile("\\d");

Process proc = Runtime.getRuntime().exec(new String[] {

"c:\\pstools\\psservice.exe", "query", "A service name"

});

BufferedReader lReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));

String lLine;

while ((lLine = lReader.readLine()) != null) {

if (lLine.indexOf("STATE") >= 0) {

Matcher lM = pattern.matcher(lLine);

if (lM.find()) {

if (lM.group().equals("4")) {

System.out.println("Service is running");

} else {

System.out.println("Some other service state");

}

}

return;

}

}

herrena at 2007-7-15 16:20:11 > top of Java-index,Archived Forums,Socket Programming...
# 4

Okay, thats a beginning. I think I can use this now, but later I will need a plattform independent version. I already found "psservice", but there is also a utility that comes with windows, command "scm", maybe I will also do some tests with this, so I do not need to distribute an Exe-File with my program. Thanks so far.

If anybody has some better ideas, I would be glad, If you could tell me.

Pirf2a at 2007-7-15 16:20:11 > top of Java-index,Archived Forums,Socket Programming...
# 5

> but later I will need a plattform independent

> version.

It is not possible to have a plattform independent version if you want to check the states of windows-NT services (hint: the word "windows"). So if you want a program that work on several plattforms, you need to have several plattform-specific codes and switch between them according to the plattform that runs.

herrena at 2007-7-15 16:20:11 > top of Java-index,Archived Forums,Socket Programming...
# 6

I think it should be possible to build a scanner, that runs plattform independent - since it should not scan the machine where itself is running. Of course I need plattform specific code for the targets. First goal is, to build a java applet, that runs on ANY os. Then there will be scanning plugins for remote machines. There already is a ping-plugin. Now I am building this windows-services plugin (which better should be applied only on windows-targets), and later on I could also need a solaris-process plugin.

Pirf2a at 2007-7-15 16:20:11 > top of Java-index,Archived Forums,Socket Programming...