Class WinServices

java.lang.Object
com.install4j.api.windows.service.WinServices

public class WinServices extends Object
Collection of static methods to manipulate Windows services
  • Constructor Details

    • WinServices

      public WinServices()
  • Method Details

    • start

      public static void start(String serviceName, String... parameters) throws ServiceException
      Starts a service. To successfully call this methods you have to request privileges first.
      Parameters:
      serviceName - the name of the service
      parameters - optional parameters
      Throws:
      ServiceException - a ServiceNotFoundException in case serviceName does not refer to the existing service, an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code
    • stop

      public static void stop(String serviceName) throws ServiceException
      Stops a service with a default timeout of 30s.
      Throws:
      ServiceException
      See Also:
    • stop

      public static void stop(String serviceName, int minimumWaitTime) throws ServiceException
      Stops a service. To successfully call this methods you have to request privileges first.
      Parameters:
      serviceName - the name of the service
      minimumWaitTime - the minimum time in milliseconds that will be waited for the service to shut down.
      Throws:
      ServiceException - a ServiceNotFoundException in case serviceName does not refer to the existing service, an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code
    • install

      public static void install(String serviceName, ServiceConfiguration configuration) throws ServiceException
      Installs a service. To successfully call this methods you have to request privileges first.
      Parameters:
      serviceName - the name of the service
      configuration - the configuration of the service. At least the binaryName property must be set.
      Throws:
      ServiceException - an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code
    • change

      public static void change(String serviceName, ServiceConfiguration configuration) throws ServiceException
      Changes a service configuration. To successfully call this methods you have to request privileges first.
      Parameters:
      serviceName - the name of the service
      configuration - the configuration of the service. All properties that are not set or set to null won't be changed.
      Throws:
      ServiceException - a ServiceNotFoundException in case serviceName does not refer to the existing service, an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code
    • uninstall

      public static void uninstall(String serviceName) throws ServiceException
      Uninstalls a service. To successfully call this methods you have to request privileges first.
      Parameters:
      serviceName - the name of the service
      Throws:
      ServiceException - a ServiceNotFoundException in case serviceName does not refer to the existing service, an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code
    • isRunning

      public static boolean isRunning(String serviceName) throws ServiceException
      Checks if a service is currently running.
      Parameters:
      serviceName - the name of the service
      Returns:
      true if running
      Throws:
      ServiceException - a ServiceNotFoundException in case serviceName does not refer to the existing service, an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code
    • getStartType

      public static ServiceStartType getStartType(String serviceName) throws ServiceException
      Returns the start type of a service.
      Parameters:
      serviceName - the name of the service
      Returns:
      a ServiceStartType value
      Throws:
      ServiceException - a ServiceNotFoundException in case serviceName does not refer to the existing service, an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code
    • getBinary

      public static String getBinary(String serviceName) throws ServiceException
      Returns the registered binary of a service.
      Parameters:
      serviceName - the name of the service
      Returns:
      the binary name. Can include quotes and arguments if the service was registered like this..
      Throws:
      ServiceException - a ServiceNotFoundException in case serviceName does not refer to the existing service, an ServiceAccessException if you don't have sufficient privileges or a generic exception with a Win32 error code