Re: how to start system services...????
Tuesday, November 5, 2002 04:21 AM
Assuming you are talking about Windows services:
A very basic solution would be to use Runtime.exec to execute a DOS command, read the output to determine success (0) or failure (non zero) of the command.
Trying to start a service already running shd write an error to stdout or stdin. Similarly trying to stop a service already stopped will give an error. On the other hand, on successful start/stop you should be able to get an output code of zero.
Use getOutputStram(), getErrorStream() methods of Process class to fetch return err descriptions, use exitValue() for return code of the process.
General format for a DOS cmd using exec() is:
"cmd.exe /C net start MyService" or similar.
If this is too basic for you, consider writing native C code for this using win32 APIs and calling it via JNI.