我的任务是使用java获取在Windows中运行的特定服务的详细信息。我能够获得服务状态,但我发现没有任何显示使用java的模式(自动,手动)。
如何获得服务模式?
这是我用来获取Windows服务状态的代码 -
String status = "";
Process p = Runtime.getRuntime().exec("sc \\\\" + host + " query \"" + serviceName + "\"");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
if (line.trim().startsWith("STATE")) {
boolean state = line.contains("RUNNING");
if (state)
status = "Running";
else
status = "Stopped";
}
line = reader.readLine();
}
答案 0 :(得分:0)
Ty执行此命令:
sc qc <service_name>
sc qc prgnDiscAgent
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: prgnDiscAgent
TYPE : 110 WIN32_OWN_PROCESS (interactive)
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : "C:\Program Files (x86)\Hewlett-Packard\Discovery Agent\bin32\discagnt.exe"
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : HP DDMI Agent
DEPENDENCIES :
SERVICE_START_NAME : LocalSystem