Here is the situation:
I have been called upon to work with InstallAnywhere 8, a Java-based installer IDE, of sorts, that allows starting and stopping of windows services, but has no built-in method to query their states. Fortunately, it allows you to create custom actions in Java which can be called at any time during the installation process (by way of what I consider to be a rather convoluted API).
I just need something that will tell me if a specific service is started or stopped.
The IDE also allows calling batch scripts, so this is an option as well, although once the script is run, there is almost no way to verify that it succeeded, so I'm trying to avoid that.
Any suggestions or criticisms are welcome.
I have had some luck in the past with the Java Service Wrapper. Depending upon your situation you may need to pay in order to use it. But it offers a clean solution that supports Java and could be used in the InstallAnywhere environment with (I think) little trouble. This will also allow you to support services on Unix boxes as well.
http://wrapper.tanukisoftware.org/doc/english/download.jsp
A shot in the dark but take a look at your Install Anywhere java documentation.
Specifically,
/javadoc/com/installshield/wizard/platform/win32/Win32Service.html
The class:
The method:
During startup, create a file with File.deleteOnExit().
Check for the existence of the file in your scripts.
here's what I had to do. It's ugly, but it works beautifully.
runProcess
is a private method that runs the given string as a command line process and returns the resulting output. As I said, ugly, but works. Hope this helps.Here's a straignt C# / P/Invoke solution.
Based on the other answers I constructed the following code to check for Windows Service status: