2017-06-02 4 views
0

Ma tâche consiste à obtenir les détails des services particuliers s'exécutant dans Windows en utilisant java. Je suis en mesure d'obtenir le statut de service mais je n'ai rien trouvé qui montre le mode (automatique, manuel) en utilisant Java.Obtenir le mode des services Windows en utilisant java

Comment obtenir le mode d'un service?

C'est le code que je utilise pour obtenir le statut des fenêtres

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(); 
} 

Répondre

0

de Ty pour exécuter cette commande:

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 
+0

Il a travaillé. Merci!. –