You can formulate a Command Prompt script to start, stop, and check status on a service using a String Array:
// start service
String[] script = {"cmd.exe", "/c", "sc", "start", SERVICE_NAME};
// stop service
String[] script = {"cmd.exe", "/c", "sc", "stop", SERVICE_NAME};
// check whether service is running or not
String[] script = {"cmd.exe", "/c", "sc", "query", APP_SERVICE_NAME, "|", "find", "/C", ""RUNNING""};
Execute scripts using the following:
Process process = Runtime.getRuntime().exec(script);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…