Find status of Windows service from Java application?

前端 未结 3 631
忘了有多久
忘了有多久 2021-01-13 05:59

How to check the status of the windows services from a java program?

3条回答
  •  礼貌的吻别
    2021-01-13 06:25

    At the very least you should be able to launch a cmd.exe process with the command sc query service-name and parse the output to determine the status. Not pretty, but lacking a Java API to the Windows service manager this would be a viable alternative.

    EDIT - Read the Javadoc for java.lang.ProcessBuilder, which will allow you to execute an external command. You should probably set the redirectErrorStream property so that you don't have to handle two input streams (stdout and stderr), making for a much simpler design.

提交回复
热议问题