From 9489428e36d9b46234eccb641ec25bba506da935 Mon Sep 17 00:00:00 2001 From: idk Date: Mon, 19 Sep 2022 01:44:29 -0400 Subject: [PATCH] enable getting service state as both an int and as a string, test uppercase and lowercase queries, test a service we know is there, test a service with it's name and it's registry entry --- java/net/i2p/router/WindowsServiceUtil.java | 25 +++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/java/net/i2p/router/WindowsServiceUtil.java b/java/net/i2p/router/WindowsServiceUtil.java index 6f227c7..f3552e5 100644 --- a/java/net/i2p/router/WindowsServiceUtil.java +++ b/java/net/i2p/router/WindowsServiceUtil.java @@ -69,18 +69,25 @@ public class WindowsServiceUtil { } return statePrefix; } - public static String getServiceState(String serviceName) { + public static int getServiceStateInt(String serviceName) { // String statePrefix = "STATE : "; String qResult = queryService(serviceName); String statePrefix = getStatePrefix(qResult); // check that the temp string contains the status prefix int ix = qResult.indexOf(statePrefix); - String stateString = "uninstalled"; if (ix >= 0) { // compare status number to one of the states String stateStr = qResult.substring(ix + statePrefix.length(), ix + statePrefix.length() + 1); int state = Integer.parseInt(stateStr); + return state; + } + return -2; + } + + public static String getServiceState(String serviceName) { + String stateString = "uninstalled"; + int state = getServiceStateInt(serviceName); switch (state) { case (1): // service stopped stateString = "stopped"; @@ -95,11 +102,21 @@ public class WindowsServiceUtil { stateString = "started"; break; } - } return stateString; } public static void main(String args[]) { String state = getServiceState("i2p"); - System.out.println("state: " + state); + int stateInt = getServiceStateInt("i2p"); + System.out.println("state: " + state + " code: " + stateInt); + String State = getServiceState("I2P"); + int StateInt = getServiceStateInt("I2P"); + System.out.println("state: " + State + " code: " + StateInt); + String dhcpstate = getServiceState("DHCP Client"); + int dhcpstateInt = getServiceStateInt("DHCP Client"); + System.out.println("state: " + dhcpstate + " code: " + dhcpstateInt); + String dstate = getServiceState("Dhcp"); + int dstateInt = getServiceStateInt("Dhcp"); + System.out.println("state: " + dstate + " code: " + dstateInt); + } }