detect all Windows service states
This commit is contained in:
@ -52,7 +52,7 @@ class WinUpdateProcess implements Runnable {
|
|||||||
// ProcessBuilder to run the installer.
|
// ProcessBuilder to run the installer.
|
||||||
ProcessBuilder pb = new ProcessBuilder(
|
ProcessBuilder pb = new ProcessBuilder(
|
||||||
file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath());
|
file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath());
|
||||||
Map<String, String> env = pb.environment();
|
Map<String, String> env = pb.environment();
|
||||||
env.put("OLD_I2P_VERSION", version);
|
env.put("OLD_I2P_VERSION", version);
|
||||||
env.remove("RESTART_I2P");
|
env.remove("RESTART_I2P");
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class WindowsServiceUtil {
|
|||||||
if (indexOfState >= 0) {
|
if (indexOfState >= 0) {
|
||||||
int indexOfColon = qResult.indexOf(":", indexOfState);
|
int indexOfColon = qResult.indexOf(":", indexOfState);
|
||||||
statePrefix = "STATE";
|
statePrefix = "STATE";
|
||||||
for (int f = indexOfState+5; f < indexOfColon; f++) {
|
for (int f = indexOfState + 5; f < indexOfColon; f++) {
|
||||||
statePrefix += " ";
|
statePrefix += " ";
|
||||||
}
|
}
|
||||||
statePrefix += ": ";
|
statePrefix += ": ";
|
||||||
@ -83,24 +83,33 @@ public class WindowsServiceUtil {
|
|||||||
}
|
}
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getServiceState(String serviceName) {
|
public static String getServiceState(String serviceName) {
|
||||||
String stateString = "uninstalled";
|
String stateString = "uninstalled";
|
||||||
int state = getServiceStateInt(serviceName);
|
int state = getServiceStateInt(serviceName);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case (1): // service stopped
|
case (1): // service stopped
|
||||||
stateString = "stopped";
|
stateString = "stopped";
|
||||||
break;
|
break;
|
||||||
case (2): // service starting
|
case (2): // service starting
|
||||||
stateString = "starting";
|
stateString = "starting";
|
||||||
break;
|
break;
|
||||||
case (3): // don't know yet
|
case (3): // service stopping
|
||||||
// stateString = "started";
|
stateString = "stopping";
|
||||||
break;
|
break;
|
||||||
case (4): // service started
|
case (4): // service started
|
||||||
stateString = "started";
|
stateString = "started";
|
||||||
break;
|
break;
|
||||||
}
|
case (5): // service resuming from pause
|
||||||
|
stateString = "resuming";
|
||||||
|
break;
|
||||||
|
case (6): // service pausing
|
||||||
|
stateString = "pausing";
|
||||||
|
break;
|
||||||
|
case (7): // service paused
|
||||||
|
stateString = "paused";
|
||||||
|
break;
|
||||||
|
}
|
||||||
return stateString;
|
return stateString;
|
||||||
}
|
}
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
@ -108,6 +117,6 @@ public class WindowsServiceUtil {
|
|||||||
// this is the correct call.
|
// this is the correct call.
|
||||||
String state = getServiceState("i2p");
|
String state = getServiceState("i2p");
|
||||||
int stateInt = getServiceStateInt("i2p");
|
int stateInt = getServiceStateInt("i2p");
|
||||||
System.out.println("i2p state: " + state + " code: " + stateInt);
|
System.out.println("i2p state: " + state + " code: " + stateInt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user