Class WinServices
java.lang.Object
com.install4j.api.windows.service.WinServices
Collection of static methods to manipulate Windows services
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidchange(String serviceName, ServiceConfiguration configuration) Changes a service configuration.static StringReturns the registered binary of a service.static ServiceStartTypegetStartType(String serviceName) Returns the start type of a service.static voidinstall(String serviceName, ServiceConfiguration configuration) Installs a service.static booleanisInstalled(String serviceName) Checks if a service is installed.static booleanChecks if a service is currently running.static voidStarts a service.static voidStops a service with a default timeout of 30 s.static voidStops a service.static voidUninstalls a service.
-
Constructor Details
-
WinServices
public WinServices()
-
-
Method Details
-
start
Starts a service. To successfully call this method, you have to request privileges first.- Parameters:
serviceName- the name of the serviceparameters- optional parameters- Throws:
ServiceException- aServiceNotFoundExceptionin case serviceName does not refer to the existing service, anServiceAccessExceptionif you don't have sufficient privileges or a generic exception with a Win32 error code
-
stop
Stops a service with a default timeout of 30 s.- Throws:
ServiceException- See Also:
-
stop
Stops a service. To successfully call this method, you have to request privileges first.- Parameters:
serviceName- the name of the serviceminimumWaitTime- the minimum time in milliseconds that will be waited for the service to shut down.- Throws:
ServiceException- aServiceNotFoundExceptionin case serviceName does not refer to the existing service, anServiceAccessExceptionif 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 method, you have to request privileges first.- Parameters:
serviceName- the name of the serviceconfiguration- the configuration of the service. At least the binaryName property must be set.- Throws:
ServiceException- anServiceAccessExceptionif 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 method, you have to request privileges first.- Parameters:
serviceName- the name of the serviceconfiguration- the configuration of the service. All properties that are not set or set tonullwon't be changed.- Throws:
ServiceException- aServiceNotFoundExceptionin case serviceName does not refer to the existing service, anServiceAccessExceptionif you don't have sufficient privileges or a generic exception with a Win32 error code
-
uninstall
Uninstalls a service. To successfully call this method, you have to request privileges first.- Parameters:
serviceName- the name of the service- Throws:
ServiceException- aServiceNotFoundExceptionin case serviceName does not refer to the existing service, anServiceAccessExceptionif you don't have sufficient privileges or a generic exception with a Win32 error code
-
isRunning
Checks if a service is currently running.- Parameters:
serviceName- the name of the service- Returns:
trueif running- Throws:
ServiceException- aServiceNotFoundExceptionin case serviceName does not refer to the existing service, anServiceAccessExceptionif you don't have sufficient privileges or a generic exception with a Win32 error code
-
getStartType
Returns the start type of a service.- Parameters:
serviceName- the name of the service- Returns:
- a
ServiceStartTypevalue - Throws:
ServiceException- aServiceNotFoundExceptionin case serviceName does not refer to the existing service, anServiceAccessExceptionif you don't have sufficient privileges or a generic exception with a Win32 error code
-
isInstalled
Checks if a service is installed.- Parameters:
serviceName- the name of the service- Returns:
trueif the service is installed,falseotherwise- Throws:
ServiceException- aServiceAccessExceptionif you don't have sufficient privileges or a generic exception with a Win32 error code
-
getBinary
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- aServiceNotFoundExceptionin case serviceName does not refer to the existing service, anServiceAccessExceptionif you don't have sufficient privileges or a generic exception with a Win32 error code
-