# WinServices

Import: `import com.install4j.api.windows.service.WinServices;`

```java
public class WinServices
```

Collection of static methods to manipulate Windows services

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`start(String, String[])`](#start-string-string) | `void` | Starts a service. |
| [`stop(String)`](#stop-string) | `void` | Stops a service with a default timeout of 30 s. |
| [`stop(String, int)`](#stop-string-int) | `void` | Stops a service. |
| [`install(String, ServiceConfiguration)`](#install-string-serviceconfiguration) | `void` | Installs a service. |
| [`change(String, ServiceConfiguration)`](#change-string-serviceconfiguration) | `void` | Changes a service configuration. |
| [`uninstall(String)`](#uninstall-string) | `void` | Uninstalls a service. |
| [`isRunning(String)`](#isrunning-string) | `boolean` | Checks if a service is currently running. |
| [`getStartType(String)`](#getstarttype-string) | `ServiceStartType` | Returns the start type of a service. |
| [`isInstalled(String)`](#isinstalled-string) | `boolean` | Checks if a service is installed. |
| [`getBinary(String)`](#getbinary-string) | `String` | Returns the registered binary of a service. |

### start(String, String[])

```java
public static void start(String serviceName, String... parameters) throws ServiceException
```

Starts a service. To successfully call this method, you have to request privileges first.


**Parameters:**

- `serviceName` — the name of the service
- `parameters` — optional parameters

**Throws:**

- `ServiceException` — a [`ServiceNotFoundException`](ServiceNotFoundException.md) in case serviceName does not refer to the existing service,
an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### stop(String)

```java
public static void stop(String serviceName) throws ServiceException
```

Stops a service with a default timeout of 30 s.


**See also:**

- [WinServices.stop](WinServices.md#stop-string-int)

### stop(String, int)

```java
public static void stop(String serviceName, int minimumWaitTime) throws ServiceException
```

Stops a service. To successfully call this method, you have to request privileges first.


**Parameters:**

- `serviceName` — the name of the service
- `minimumWaitTime` — the minimum time in milliseconds to wait for the service to shut down.

**Throws:**

- `ServiceException` — a [`ServiceNotFoundException`](ServiceNotFoundException.md) in case serviceName does not refer to the existing service,
an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### install(String, ServiceConfiguration)

```java
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 service
- `configuration` — the configuration of the service. At least the binaryName property must be set.

**Throws:**

- `ServiceException` — an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### change(String, ServiceConfiguration)

```java
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 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`](ServiceNotFoundException.md) in case serviceName does not refer to the existing service,
an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### uninstall(String)

```java
public static void uninstall(String serviceName) throws ServiceException
```

Uninstalls a service. To successfully call this method, you have to request privileges first.


**Parameters:**

- `serviceName` — the name of the service

**Throws:**

- `ServiceException` — a [`ServiceNotFoundException`](ServiceNotFoundException.md) in case serviceName does not refer to the existing service,
an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### isRunning(String)

```java
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`](ServiceNotFoundException.md) in case serviceName does not refer to the existing service,
an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### getStartType(String)

```java
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`](ServiceStartType.md) value

**Throws:**

- `ServiceException` — a [`ServiceNotFoundException`](ServiceNotFoundException.md) in case serviceName does not refer to the existing service,
an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### isInstalled(String)

```java
public static boolean isInstalled(String serviceName)
```

Checks if a service is installed.


**Parameters:**

- `serviceName` — the name of the service

**Returns:** `true` if the service is installed, `false` otherwise

**Throws:**

- `ServiceException` — a [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

### getBinary(String)

```java
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`](ServiceNotFoundException.md) in case serviceName does not refer to the existing service,
an [`ServiceAccessException`](ServiceAccessException.md) if you don't have sufficient privileges or a generic exception with a Win32 error code

## Constructors

| Signature | Description |
|---|---|
| [`WinServices()`](#winservices) |  |

### WinServices()

```java
public WinServices()
```

